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

overview.md

147 lines7.6 KB

1---
2title: Overview
3id: overview
4order: 1
5description: "TanStack AI is a type-safe TypeScript SDK for AI features. It streams chat, calls tools, and works with any provider and any UI 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 TypeScript SDK for streaming chat, tool calls, and media generation. Swap the provider or the UI framework without rewriting the call.
18​
19TanStack AI gives you one typed API for all of that. Your server talks to the provider through an adapter. Your UI reads the stream through a hook for your framework.
20​
21Start here: [Quick Start](./quick-start). You get a streaming chat in about 5 minutes.
22​
23## Who it is for
24​
25- **You are new and want to try it.** Go to [Quick Start](./quick-start).
26- **You have chat and want one more feature.** Start with [Tools](../tools/tools), [Structured Outputs](../structured-outputs/overview), or [Persistence](../persistence/overview).
27- **You want to pick or switch a provider.** Open the [OpenRouter adapter](../adapters/openrouter) for 300+ models with one key, or any page under Adapters.
28- **You run it in production or extend it.** Read [Middleware](../advanced/middleware), [Resumable Streams](../resumable-streams/overview), and [Sandboxes](../sandbox/overview).
29- **You come from 0.x or the Vercel AI SDK.** Read [Upgrade to 1.0](../migration/v1) or [TanStack AI vs Vercel AI SDK](../comparison/vercel-ai-sdk).
30​
31## What you get
32​
33- **Type safety.** Tool inputs, model options, and message parts are typed from your schemas and the model you pick.
34- **Streaming.** Responses stream token by token, from the server route to the UI.
35- **Isomorphic tools.** Define a tool once with `toolDefinition()`. Run it on the server with `.server()` or in the browser with `.client()`.
36- **Any provider.** OpenRouter, OpenAI, Anthropic, Gemini, Ollama, and more. Swap the adapter, keep the code.
37- **Any framework.** React, Vue, Solid, Svelte, Preact, Angular, Octane, Remix, or no framework.
38​
39Later, when you need them:
40​
41- **Approvals.** Pause a tool call until a person says yes. See [Tool Approval](../tools/tool-approval).
42- **Typed decisions.** Ask `choice`, `score`, and `boolean` questions with `decide()`. See [Evaluate](../evaluate/evaluate).
43- **Bring your own key.** Users paste their own provider key in the browser. See [Bring Your Own Key](../advanced/byok).
44​
45## How it works
46​
47A chat has two halves:
48​
491. **The server** calls `chat()` with an adapter and the messages. It returns the stream as a `Response`.
502. **The client** calls a hook such as `useChat()`. The hook sends messages to your server route and renders the parts as they arrive.
51​
52Tools fit into the same loop. When the model calls a tool, TanStack AI runs it, sends the result back to the model, and keeps streaming.
53​
54```typescript
55import { chat, toolDefinition } from '@tanstack/ai'
56import { openaiText } from '@tanstack/ai-openai'
57import { z } from 'zod'
58​
59const products = [
60 { id: '1', name: 'Blue mug' },
61 { id: '2', name: 'Red mug' },
63​
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​
71const getProducts = getProductsDef.server(async ({ query }) =>
72 products.filter((product) => product.name.toLowerCase().includes(query)),
74​
75const stream = chat({
76 adapter: openaiText('gpt-6.1-sol'),
77 messages: [{ role: 'user', content: 'Find mugs' }],
78 threadId: 'thread-1',
79 tools: [getProducts],
80})
81```
82​
83## Learn by building
84​
85Each tutorial builds one small app from start to finish:
86​
87- [Basic Chat](../tutorials/basic-chat): a streaming React chat. The key stays in the browser tab.
88- [Generate Image](../tutorials/generate-image): an image from a prompt.
89- [Streaming Structured Table](../tutorials/streaming-structured-table): a typed table that fills in from `chat({ outputSchema })`.
90- [Subagents](../tutorials/subagents): a researcher, an SEO agent, and a writer in one blog-writing chat.
91- [Build an MCP Server](../tutorials/mcp-server): serve a tool, a resource, and a prompt.
92- [Computer Use](../tutorials/computer-use): let the model use a web page from screenshots.
93​
94## Reference
95​
96### Where it runs
97​
98The core works in any JavaScript runtime. These hosts are common:
99​
100| Host | Notes |
101| --- | --- |
102| TanStack Start | React Start or Solid Start. |
103| Next.js | API routes and App Router. |
104| React Router v7 | Loaders and actions. |
105| Remix 3 | Controllers return SSE. Call `createChat` in a `clientEntry` island. |
106| Express | Node.js server. See [Quick Start: Server Only](./quick-start-server). |
107| React Native / Expo | `useChat` with an absolute server URL and an XHR transport. See [Quick Start: React Native](./quick-start-react-native). |
108​
109### Core packages
110​
111| Package | What it does |
112| --- | --- |
113| `@tanstack/ai` | The core. `chat()`, streaming, the tool system, agent loop strategies, and adapter types. Model options and content types (text, image, audio, video, document) are typed per model. |
114| `@tanstack/ai-client` | A headless chat client for any framework. It holds message state, streams through connection adapters (SSE, HTTP stream, custom), runs server and client tools, and handles approvals. |
115| `@tanstack/ai-react` | `useChat` for React, with approvals and typed messages through `InferChatMessages`. |
116| `@tanstack/ai-solid` | `useChat` for Solid, with the same features as React. |
117| `@tanstack/ai-octane` | `useChat` for Octane, with the same hook names as `@tanstack/ai-react`. The Octane plugin compiles it from `.tsrx` source. |
118​
119Vue, Svelte, Preact, Angular, and Remix have their own packages too. See the [API reference](../api/ai) for each one.
120​
121### Provider adapters
122​
123Each adapter is its own package. Install only the ones you use.
124​
125| Package | Provider |
126| --- | --- |
127| `@tanstack/ai-openrouter` | OpenRouter. 300+ models with one API key. A good first pick. |
128| `@tanstack/ai-openai` | OpenAI (GPT models). |
129| `@tanstack/ai-anthropic` | Anthropic (Claude). |
130| `@tanstack/ai-gemini` | Google Gemini. |
131| `@tanstack/ai-vertex` | Gemini on Google Vertex AI. For Claude, Grok, and Mistral on Vertex, use `@tanstack/ai-anthropic/vertex`, `@tanstack/ai-grok/vertex`, and `@tanstack/ai-mistral/vertex`. |
132| `@tanstack/ai-ollama` | Ollama (local models). |
133| `@tanstack/ai-groq` | Groq. |
134| `@tanstack/ai-grok` | xAI Grok. |
135| `@tanstack/ai-bedrock` | Amazon Bedrock (Claude, Nova, Llama, and more through AWS). |
136| `@tanstack/ai-byteplus` | BytePlus (Seed chat, Seedance video, Seedream image, Seed Speech). |
137| `@tanstack/ai-fal` | fal (image and video generation). |
138| `@tanstack/ai-reactor` | Reactor (live world and video generation: Orbis, Happy Oyster, LingBot, Helios, FastH3). |
139| `@tanstack/ai-worldlabs` | World Labs Marble (persistent 3D world generation). |
140| `@tanstack/ai-llmgateway` | LLM Gateway. Hundreds of models through one OpenAI-compatible endpoint. You can host it yourself. |
141| `@tanstack/ai-cloudflare` | Cloudflare Workers AI (chat, embeddings, image, speech, transcription, evaluate) and AI Gateway routing. |
142| `@tanstack/ai-neon` | Neon AI Gateway (Claude, GPT, Gemini, and open models, plus embeddings, through one Neon credential). |
143| `@tanstack/ai-typesafe` | TypeSafe Jev (typed evaluate decisions). |
144| `@tanstack/ai-ollaya` | Local Ollaya `laya` models for typed evaluate decisions. No API key. |
145| `@tanstack/ai-lovable` | Lovable AI Gateway (Google and OpenAI chat, image, video, embeddings, and speech through one project key). |
146​
147The Adapters section of the sidebar has a page for each provider.