Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

overview.md

155 lines7.0 KB

1---
2title: Overview
3id: overview
4order: 1
5description: "TanStack AI is a type-safe, provider-agnostic TypeScript SDK for building streaming chat, tool calling, and AI features that work across any framework."
6keywords:
7 - tanstack ai
8 - ai sdk
9 - typescript ai
10 - streaming chat
11 - tool calling
12 - isomorphic tools
13 - framework agnostic
14 - llm sdk
15---
16​
17TanStack AI is a lightweight, type-safe SDK for building production-ready AI experiences. Its framework-agnostic core provides type-safe tool/function calling, streaming responses, and first-class React and Solid integrations, with adapters for multiple LLM providers — enabling predictable, composable, and testable AI features across any stack.
18​
19Build a streaming React chat in [Basic Chat](../tutorials/basic-chat). The key stays in the tab.
20​
21Serve a tool, a resource, and a prompt in [Build an MCP Server](../tutorials/mcp-server).
22​
23Generate an image from a prompt in [Generate Image](../tutorials/generate-image).
24​
25Stream a typed table from `chat({ outputSchema })` in [Streaming Structured Table](../tutorials/streaming-structured-table).
26​
27Add three named agents (researcher, SEO, and writer) to a blog-writing chat in [Subagents](../tutorials/subagents).
28​
29Let the model use a web page from screenshots in [Computer Use](../tutorials/computer-use).
30​
31## Key Features
32​
33- ✅ **Type-Safe** - Full TypeScript support with Zod schema inference
34- ✅ **Streaming** - Built-in streaming support for real-time responses
35- ✅ **Isomorphic Tools** - Define once with `toolDefinition()`, implement with `.server()` or `.client()`
36- ✅ **Framework Agnostic** - Core library works anywhere
37- ✅ **Multiple Providers** - OpenRouter, OpenAI, Anthropic, Gemini, Ollama, and more
38- ✅ **Typed Decisions** - Ask `choice`, `score`, and `boolean` questions with `decide()`
39- ✅ **Approval Flow** - Built-in support for tool approval workflows
40- ✅ **Automatic Execution** - Both server and client tools execute automatically
41​
42Users can paste their own provider API keys in the browser. See [Bring Your Own Key](../advanced/byok).
43​
44## Framework Agnostic
45​
46The framework-agnostic core of TanStack AI provides the building blocks for creating AI experiences in any environment, including:
47​
48- **Next.js** - API routes and App Router
49- **TanStack Start** - React Start or Solid Start (recommended!)
50- **Remix 3** - Controllers return SSE. Call `createChat` in a `clientEntry` island
51- **React Native / Expo** - Native chat screens with `useChat`, absolute server URLs, and XHR streaming transports
52- **Express** - Node.js server
53- **React Router v7** - Loaders and actions
54​
55TanStack AI lets you define a tool once and provide environment-specific implementations. Using `toolDefinition()` to declare the tool's input/output types and the server behavior with `.server()` (or a client implementation with `.client()`). These isomorphic tools can be invoked from the AI runtime regardless of framework.
56​
57```typescript
58import { chat, toolDefinition } from '@tanstack/ai'
59import { openaiText } from '@tanstack/ai-openai'
60import { z } from 'zod'
61import { db } from './db'
62​
63// Define a tool
64const getProductsDef = toolDefinition({
65 name: 'getProducts',
66 description: 'Search for products by query',
67 inputSchema: z.object({ query: z.string() }),
68 outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
69})
70​
71// Create server implementation
72const getProducts = getProductsDef.server(async ({ query }) => {
73 return await db.products.search(query)
74})
75​
76// Use in AI chat
77chat({
78 adapter: openaiText('gpt-5.2'),
79 messages: [{ role: 'user', content: 'Find products' }],
80 tools: [getProducts]
81})
82```
83​
84## Core Packages
85​
86The TanStack AI ecosystem consists of several packages:
87​
88### `@tanstack/ai`
89The core AI library that provides:
90- AI adapter interface for connecting to LLM providers
91- Chat completion and streaming
92- Isomorphic tool/function calling system
93- Agent loop strategies
94- Type-safe tool definitions with `toolDefinition()`
95- Type-safe Model Options based on adapter & model selection
96- Type-safe content modalities (text, image, audio, video, document) based on model capabilities
97​
98### `@tanstack/ai-client`
99A framework-agnostic headless client for managing chat state:
100- Message management with full type safety
101- Streaming support
102- Connection adapters (SSE, HTTP stream, custom)
103- Automatic tool execution (server and client)
104- Tool approval flow handling
105​
106### `@tanstack/ai-react`
107React hooks for TanStack AI:
108- `useChat` hook for chat interfaces
109- Automatic state management
110- Tool approval flow support
111- Type-safe message handling with `InferChatMessages`
112​
113### `@tanstack/ai-solid`
114Solid hooks for TanStack AI:
115- `useChat` hook for chat interfaces
116- Automatic state management
117- Tool approval flow support
118- Type-safe message handling with `InferChatMessages`
119​
120### `@tanstack/ai-octane`
121Octane hooks for TanStack AI:
122- `useChat` hook for chat interfaces
123- Same hook names as `@tanstack/ai-react`
124- Compiled by the Octane plugin from `.tsrx` source
125​
126## Adapters
127​
128With the help of adapters, TanStack AI can connect to various LLM providers. Available adapters include:
129​
130- **@tanstack/ai-openrouter** - OpenRouter (300+ models via a single API key — recommended)
131- **@tanstack/ai-openai** - OpenAI (GPT series)
132- **@tanstack/ai-anthropic** - Anthropic (Claude)
133- **@tanstack/ai-gemini** - Google Gemini
134- **@tanstack/ai-vertex** - Gemini on Google Vertex AI. Claude, Grok, and Mistral on Vertex live on `@tanstack/ai-anthropic/vertex`, `@tanstack/ai-grok/vertex`, and `@tanstack/ai-mistral/vertex`.
135- **@tanstack/ai-ollama** - Ollama (local models)
136- **@tanstack/ai-groq** - Groq
137- **@tanstack/ai-grok** - xAI Grok
138- **@tanstack/ai-bedrock** - Amazon Bedrock (Claude, Nova, Llama, and more via AWS)
139- **@tanstack/ai-byteplus** - BytePlus (Seed chat, Seedance video, Seedream image, Seed Speech)
140- **@tanstack/ai-fal** - fal (image & video generation)
141- **@tanstack/ai-reactor** - Reactor (live world and video generation: Orbis, Happy Oyster, LingBot, Helios, FastH3)
142- **@tanstack/ai-worldlabs** - World Labs Marble (persistent 3D world generation)
143- **@tanstack/ai-llmgateway** - LLM Gateway (hundreds of models via one OpenAI-compatible endpoint, self-hostable)
144- **@tanstack/ai-cloudflare** - Cloudflare Workers AI (chat, embeddings, image, speech, transcription, evaluate) and AI Gateway routing
145- **@tanstack/ai-typesafe** - TypeSafe Jev (typed evaluate decisions)
146- **@tanstack/ai-ollaya** - local Ollaya `laya` models for typed evaluate decisions. No API key.
147- **@tanstack/ai-lovable** - Lovable AI Gateway (Google and OpenAI chat, image, video, embeddings, and speech via one project key)
148​
149## Next Steps
150​
151- [Quick Start](./quick-start) - Add streaming chat. Pick your framework at the top of the page.
152- [Quick Start: React Native](./quick-start-react-native) - Add mobile chat with Expo and a server-owned provider boundary
153- [Evaluate](../evaluate/evaluate) - Ask typed questions and branch on the answers
154- [Tools Guide](../tools/tools) - Learn about the isomorphic tool system
155- [API Reference](../api/ai) - Explore the full API