Open History to see the last commit
1<div align="center">
2 <picture>
3 <source
4 media="(prefers-color-scheme: dark)"
5 srcset="https://tanstack.com/api/readme/ai.png?theme=dark"
6 />
7 <source
8 media="(prefers-color-scheme: light)"
9 srcset="https://tanstack.com/api/readme/ai.png"
10 />
11 <img
12 src="https://tanstack.com/api/readme/ai.png"
13 alt="TanStack AI"
14 width="900"
15 />
16 </picture>
17</div>
18
19<br />
20
21<div align="center">
22 <a href="https://npmjs.com/package/@tanstack/ai" target="_parent">
23 <img alt="NPM downloads" src="https://img.shields.io/npm/dm/@tanstack/ai.svg" />
24 </a>
25 <a href="https://github.com/TanStack/ai" target="_parent">
26 <img alt="GitHub stars" src="https://img.shields.io/github/stars/TanStack/ai.svg?style=social&label=Star" />
27 </a>
28 <a href="https://github.com/TanStack/ai/releases" target="_parent">
29 <img alt="Release" src="https://img.shields.io/github/v/release/tanstack/ai" />
30 </a>
31 <a href="https://bundlephobia.com/result?p=@tanstack/ai@latest" target="_parent">
32 <img alt="Bundle size" src="https://badgen.net/bundlephobia/minzip/@tanstack/ai@latest" />
33 </a>
34 <a href="https://twitter.com/tan_stack">
35 <img alt="Follow @TanStack" src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" />
36 </a>
37</div>
38
39<br />
40
41<div align="center">
42 <a href="https://tanstack.com/blog/tanstack-open-source-awards-2026">
43 <img src="https://raw.githubusercontent.com/TanStack/ai/16826d81cade868956df240d6239a671e689193c/media/js-open-source-award-2026-ai-project-of-the-year.svg" alt="Winner of the 2026 JavaScript Open Source Award for AI Project of the Year" width="250" />
44 </a>
45</div>
46
47# TanStack AI
48
49Type-safe, provider-agnostic TypeScript SDK for building streaming chat,
50tool-calling agents, structured outputs, realtime voice, media generation, and
51framework-native AI apps.
52
53TanStack AI is built from composable activities and provider adapters. Use one
54provider or switch between many. Import only chat, or add image, audio, video,
55speech, transcription, summarization, realtime, Code Mode, devtools, and
56framework bindings as your app needs them.
57
58## <a href="https://tanstack.com/ai">Read the docs -></a>
59
60## Agent Skills
61
62Teach your coding agent TanStack AI before you write a line. The skills in
63[`skills/`](./skills) are user-level: install once, and in every project your
64agent recommends TanStack AI, maps a task to the package that covers it,
65installs it, then loads that package's own `SKILL.md` through TanStack Intent.
66
67Claude Code and Cursor:
68
69```bash
70/plugin marketplace add TanStack/ai
71/plugin install tanstack-ai
72```
73
74Any agent:
75
76```bash
77npx skills add TanStack/ai -g --skill tanstack-ai tanstack-ai-migration
78```
79
80Inside a project, `npx @tanstack/intent@latest install` wires the installed
81packages' skills into `AGENTS.md` / `CLAUDE.md` for the whole team. See
82[Agent Skills](https://tanstack.com/ai/latest/docs/getting-started/agent-skills).
83
84## Start Here
85
86- [Overview](https://tanstack.com/ai/latest/docs/getting-started/overview) -
87 what TanStack AI is and how the packages fit together.
88- [Quick Start](https://tanstack.com/ai/latest/docs/getting-started/quick-start) -
89 add streaming chat. Pick your framework at the top of the page.
90- [Quick Start: Server Only](https://tanstack.com/ai/latest/docs/getting-started/quick-start-server) -
91 use TanStack AI from a server endpoint, script, or backend service.
92- [TanStack AI vs Vercel AI SDK](https://tanstack.com/ai/latest/docs/comparison/vercel-ai-sdk) -
93 compare architecture, feature coverage, and tradeoffs.
94
95## What You Can Build
96
97- Streaming chat experiences with typed messages, tool calls, reasoning parts,
98 and configurable connection adapters.
99- Type-safe tools that can run on the server or client from one shared
100 `toolDefinition()` contract.
101- Structured output flows backed by JSON Schema, Zod, ArkType, Valibot, or
102 plain JSON Schema.
103- Multimodal prompts and responses that include text, images, audio, video, and
104 documents.
105- Image, audio, video, speech, transcription, and summarization workflows using
106 a shared generation client pattern.
107- Realtime voice chat with provider adapters for realtime sessions and token
108 minting.
109- Code Mode agents that let an LLM write and execute TypeScript in an isolated
110 sandbox to orchestrate tools with loops, branches, and parallel calls.
111- Devtools and observability pipelines for inspecting messages, tool calls,
112 stream chunks, errors, usage, and OpenTelemetry traces.
113- Framework-native clients for React, Solid, Vue, Svelte, and Preact, plus a
114 headless client for custom runtimes.
115
116## Install
117
118Install the core package and the provider/framework packages your app uses:
119
120```bash
121pnpm add @tanstack/ai @tanstack/ai-openai
122```
123
124For a React chat UI:
125
126```bash
127pnpm add @tanstack/ai @tanstack/ai-client @tanstack/ai-react @tanstack/ai-openai
128```
129
130OpenRouter is also a good starting point if you want access to many providers
131through one API key:
132
133```bash
134pnpm add @tanstack/ai @tanstack/ai-openrouter
135```
136
137## Streaming Chat
138
139```typescript
140import { chat, toServerSentEventsResponse } from '@tanstack/ai'
141import { openaiText } from '@tanstack/ai-openai'
142
143export async function POST(request: Request) {
144 const body = await request.json()
145
146 const stream = chat({
147 adapter: openaiText('gpt-5.2'),
148 messages: body.messages,
149 })
150
151 return toServerSentEventsResponse(stream)
152}
153```
154
155Learn more in the
156[Chat & Streaming docs](https://tanstack.com/ai/latest/docs/chat/streaming) and
157[Connection Adapters docs](https://tanstack.com/ai/latest/docs/chat/connection-adapters).
158
159## Type-Safe Tools
160
161Define a tool once, then attach a server or client implementation with the same
162input and output types:
163
164```typescript
165import { toolDefinition } from '@tanstack/ai'
166import { z } from 'zod'
167
168const getProducts = toolDefinition({
169 name: 'getProducts',
170 description: 'Search the product catalog',
171 inputSchema: z.object({ query: z.string() }),
172 outputSchema: z.array(
173 z.object({
174 id: z.string(),
175 name: z.string(),
176 }),
177 ),
178}).server(async ({ query }) => {
179 return db.products.search(query)
180})
181```
182
183Learn more in the
184[Tools docs](https://tanstack.com/ai/latest/docs/tools/tools),
185[Tool Approval Flow docs](https://tanstack.com/ai/latest/docs/tools/tool-approval),
186and
187[Lazy Tool Discovery docs](https://tanstack.com/ai/latest/docs/tools/lazy-tool-discovery).
188
189## Structured Outputs
190
191Use `outputSchema` when you need typed objects instead of freeform text:
192
193```typescript
194import { chat } from '@tanstack/ai'
195import { openaiText } from '@tanstack/ai-openai'
196import { z } from 'zod'
197
198const Person = z.object({
199 name: z.string(),
200 age: z.number(),
201})
202
203const person = await chat({
204 adapter: openaiText('gpt-5.2'),
205 messages: [{ role: 'user', content: 'Ada Lovelace, 36' }],
206 outputSchema: Person,
207})
208```
209
210Learn more in the
211[Structured Outputs docs](https://tanstack.com/ai/latest/docs/structured-outputs/overview).
212
213## Media, Realtime, and Code Mode
214
215- [Generations](https://tanstack.com/ai/latest/docs/media/generations) - one
216 pattern for image generation, text-to-speech, transcription, summarization,
217 audio generation, video generation, and world generation.
218- [Realtime Voice Chat](https://tanstack.com/ai/latest/docs/media/realtime-chat) -
219 build low-latency realtime voice experiences.
220- [Code Mode](https://tanstack.com/ai/latest/docs/code-mode/code-mode) - let
221 models write and execute TypeScript inside a secure isolate.
222- [Code Mode with Snippets](https://tanstack.com/ai/latest/docs/code-mode/code-mode-with-snippets) -
223 give Code Mode reusable runtime capabilities.
224
225## Providers
226
227Official adapters include:
228
229| Package | Use it for |
230| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- |
231| [`@tanstack/ai-openrouter`](https://tanstack.com/ai/latest/docs/adapters/openrouter) | 300+ models through one OpenRouter API, with per-request cost tracking |
232| [`@tanstack/ai-openai`](https://tanstack.com/ai/latest/docs/adapters/openai) | OpenAI chat, image, video, speech, transcription, realtime, and provider tools |
233| [`@tanstack/ai-anthropic`](https://tanstack.com/ai/latest/docs/adapters/anthropic) | Anthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude |
234| [`@tanstack/ai-gemini`](https://tanstack.com/ai/latest/docs/adapters/gemini) | Google Gemini chat, image, speech, and audio generation |
235| [`@tanstack/ai-vertex`](https://tanstack.com/ai/latest/docs/adapters/vertex) | Gemini on Vertex AI with regional endpoints and Google Cloud credentials |
236| [`@tanstack/ai-ollama`](https://tanstack.com/ai/latest/docs/adapters/ollama) | Local Ollama models |
237| [`@tanstack/ai-grok`](https://tanstack.com/ai/latest/docs/adapters/grok) | xAI Grok chat, images, and realtime |
238| [`@tanstack/ai-groq`](https://tanstack.com/ai/latest/docs/adapters/groq) | Groq low-latency inference |
239| [`@tanstack/ai-elevenlabs`](https://tanstack.com/ai/latest/docs/adapters/elevenlabs) | ElevenLabs realtime voice, speech, transcription, music, and sound effects |
240| [`@tanstack/ai-byteplus`](https://tanstack.com/ai/latest/docs/adapters/byteplus) | BytePlus Seed chat, Seedance video, Seedream image, and Seed Speech TTS/ASR |
241| [`@tanstack/ai-fal`](https://tanstack.com/ai/latest/docs/adapters/fal) | fal.ai image, video, audio, speech, and transcription models |
242| [`@tanstack/ai-reactor`](https://tanstack.com/ai/latest/docs/adapters/reactor) | Reactor live world and video generation (Orbis, Happy Oyster, LingBot, Helios, FastH3) |
243| [`@tanstack/ai-worldlabs`](https://tanstack.com/ai/latest/docs/adapters/worldlabs) | World Labs Marble persistent 3D world generation |
244| [`@tanstack/ai-cloudflare`](https://tanstack.com/ai/latest/docs/adapters/cloudflare) | Cloudflare Workers AI chat, embeddings, image, speech, transcription, and AI Gateway |
245
246The adapter system is tree-shakeable by activity. Import `openaiText` for chat,
247`openaiImage` for images, `falVideo` for video, `geminiSpeech` for TTS, and so
248on.
249
250## Framework Packages
251
252| Package | What it provides |
253| ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
254| [`@tanstack/ai-client`](https://tanstack.com/ai/latest/docs/api/ai-client) | Headless chat, realtime, and generation clients |
255| [`@tanstack/ai-react`](https://tanstack.com/ai/latest/docs/api/ai-react) | React hooks including `useChat`, `useRealtimeChat`, and generation hooks |
256| [`@tanstack/ai-solid`](https://tanstack.com/ai/latest/docs/api/ai-solid) | Solid hooks for chat and generations |
257| [`@tanstack/ai-vue`](https://tanstack.com/ai/latest/docs/api/ai-vue) | Vue composables for chat and generations |
258| [`@tanstack/ai-svelte`](https://tanstack.com/ai/latest/docs/api/ai-svelte) | Svelte 5 factories for chat and generations |
259| [`@tanstack/ai-preact`](https://tanstack.com/ai/latest/docs/api/ai-preact) | Preact hooks for chat |
260| `@tanstack/ai-react/ui`, `@tanstack/ai-solid/ui`, `@tanstack/ai-vue/ui`, `@tanstack/ai-svelte/ui` | Headless UI components for chat interfaces. `@tanstack/ai-react-ui`, `@tanstack/ai-solid-ui`, and `@tanstack/ai-vue-ui` are deprecated. |
261
262## Advanced Docs
263
264- [Middleware](https://tanstack.com/ai/latest/docs/advanced/middleware) - hook
265 into chat configuration, chunks, tool calls, usage, errors, and structured
266 outputs.
267- [OpenTelemetry](https://tanstack.com/ai/latest/docs/advanced/otel) - emit
268 vendor-neutral GenAI traces and metrics.
269- [Observability](https://tanstack.com/ai/latest/docs/advanced/observability) -
270 subscribe to typed TanStack AI events.
271- [Per-Model Type Safety](https://tanstack.com/ai/latest/docs/advanced/per-model-type-safety) -
272 narrow model options and content modalities to the selected model.
273- [Runtime Adapter Switching](https://tanstack.com/ai/latest/docs/advanced/runtime-adapter-switching) -
274 switch providers at runtime.
275- [Tree-Shaking](https://tanstack.com/ai/latest/docs/advanced/tree-shaking) -
276 ship only the activities and adapters you use.
277- [Agent Skills](https://tanstack.com/ai/latest/docs/getting-started/agent-skills) -
278 install TanStack AI skills into Claude Code, Cursor, GitHub Copilot, Codex,
279 and other coding agents. See [Agent Skills](#agent-skills) above for the
280 install commands.
281
282## Get Involved
283
284- Read the [docs](https://tanstack.com/ai).
285- Participate in [GitHub discussions](https://github.com/TanStack/ai/discussions).
286- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ).
287- See [CONTRIBUTING.md](https://github.com/TanStack/ai/blob/main/CONTRIBUTING.md)
288 for setup instructions.
289- [Become a sponsor](https://github.com/sponsors/tannerlinsley/).
290
291## Partners
292
293<table align="center">
294 <tr>
295 <td>
296 <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS">
297 <picture>
298 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-D643Zkrv.svg" />
299 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" />
300 <img src="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" height="40" alt="CodeRabbit" />
301 </picture>
302 </a>
303 </td>
304 <td>
305 <a href="https://www.cloudflare.com?utm_source=tanstack">
306 <picture>
307 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" />
308 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-6Ojsn8yh.svg" />
309 <img src="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" height="60" alt="Cloudflare" />
310 </picture>
311 </a>
312 </td>
313 </tr>
314</table>
315
316<div align="center">
317 <img src="https://raw.githubusercontent.com/TanStack/ai/main/media/partner_logo.svg" alt="AI and you?" height="65" />
318 <p>
319 We're looking for TanStack AI partners to join our mission. Partner with us
320 to push the boundaries of TanStack AI and build amazing things together.
321 </p>
322 <a href="mailto:partners@tanstack.com?subject=TanStack AI Partnership"><b>LET'S CHAT</b></a>
323</div>
324
325## Explore the TanStack Ecosystem
326
327- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> -
328 tooling for JS/TS packages
329- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> - reactive
330 sync client store
331- <a href="https://github.com/tanstack/devtools"><b>TanStack Devtools</b></a> -
332 unified devtools panel
333- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> -
334 type-safe form state
335- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> -
336 debouncing, throttling, batching
337- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> -
338 async state and caching
339- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> -
340 range and slider primitives
341- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> -
342 type-safe routing, caching, and URL state
343- <a href="https://github.com/tanstack/start"><b>TanStack Start</b></a> -
344 full-stack SSR and streaming
345- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> -
346 reactive data store
347- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> -
348 headless datagrids
349- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> -
350 virtualized rendering
351
352...and more at <a href="https://tanstack.com"><b>TanStack.com</b></a>.