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 threadId: body.threadId,
150 })
151
152 return toServerSentEventsResponse(stream)
153}
154```
155
156Learn more in the
157[Chat & Streaming docs](https://tanstack.com/ai/latest/docs/chat/streaming) and
158[Transports docs](https://tanstack.com/ai/latest/docs/transports/overview).
159
160## Type-Safe Tools
161
162Define a tool once, then attach a server or client implementation with the same
163input and output types:
164
165```typescript
166import { toolDefinition } from '@tanstack/ai'
167import { z } from 'zod'
168
169const getProducts = toolDefinition({
170 name: 'getProducts',
171 description: 'Search the product catalog',
172 inputSchema: z.object({ query: z.string() }),
173 outputSchema: z.array(
174 z.object({
175 id: z.string(),
176 name: z.string(),
177 }),
178 ),
179}).server(async ({ query }) => {
180 return db.products.search(query)
181})
182```
183
184Learn more in the
185[Tools docs](https://tanstack.com/ai/latest/docs/tools/tools),
186[Tool Approval Flow docs](https://tanstack.com/ai/latest/docs/tools/tool-approval),
187and
188[Lazy Tool Discovery docs](https://tanstack.com/ai/latest/docs/tools/lazy-tool-discovery).
189
190## Structured Outputs
191
192Use `outputSchema` when you need typed objects instead of freeform text:
193
194```typescript
195import { chat } from '@tanstack/ai'
196import { openaiText } from '@tanstack/ai-openai'
197import { z } from 'zod'
198
199const Person = z.object({
200 name: z.string(),
201 age: z.number(),
202})
203
204const person = await chat({
205 adapter: openaiText('gpt-5.2'),
206 messages: [{ role: 'user', content: 'Ada Lovelace, 36' }],
207 threadId: 'thread-1',
208 outputSchema: Person,
209})
210```
211
212Learn more in the
213[Structured Outputs docs](https://tanstack.com/ai/latest/docs/structured-outputs/overview).
214
215## Media, Realtime, and Code Mode
216
217- [Generations](https://tanstack.com/ai/latest/docs/media/generations) - one
218 pattern for image generation, text-to-speech, transcription, summarization,
219 audio generation, video generation, and world generation.
220- [Realtime Voice Chat](https://tanstack.com/ai/latest/docs/media/realtime-chat) -
221 build low-latency realtime voice experiences.
222- [Code Mode](https://tanstack.com/ai/latest/docs/code-mode/code-mode) - let
223 models write and execute TypeScript inside a secure isolate.
224- [Code Mode with Snippets](https://tanstack.com/ai/latest/docs/code-mode/code-mode-with-snippets) -
225 give Code Mode reusable runtime capabilities.
226
227## Providers
228
229Official adapters include:
230
231| Package | Use it for |
232| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- |
233| [`@tanstack/ai-openrouter`](https://tanstack.com/ai/latest/docs/adapters/openrouter) | 300+ models through one OpenRouter API, with per-request cost tracking |
234| [`@tanstack/ai-openai`](https://tanstack.com/ai/latest/docs/adapters/openai) | OpenAI chat, image, video, speech, transcription, realtime, and provider tools |
235| [`@tanstack/ai-anthropic`](https://tanstack.com/ai/latest/docs/adapters/anthropic) | Anthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude |
236| [`@tanstack/ai-gemini`](https://tanstack.com/ai/latest/docs/adapters/gemini) | Google Gemini chat, image, speech, and audio generation |
237| [`@tanstack/ai-vertex`](https://tanstack.com/ai/latest/docs/adapters/vertex) | Gemini on Vertex AI with regional endpoints and Google Cloud credentials |
238| [`@tanstack/ai-ollama`](https://tanstack.com/ai/latest/docs/adapters/ollama) | Local Ollama models |
239| [`@tanstack/ai-grok`](https://tanstack.com/ai/latest/docs/adapters/grok) | xAI Grok chat, images, and realtime |
240| [`@tanstack/ai-groq`](https://tanstack.com/ai/latest/docs/adapters/groq) | Groq low-latency inference |
241| [`@tanstack/ai-elevenlabs`](https://tanstack.com/ai/latest/docs/adapters/elevenlabs) | ElevenLabs realtime voice, speech, transcription, music, and sound effects |
242| [`@tanstack/ai-byteplus`](https://tanstack.com/ai/latest/docs/adapters/byteplus) | BytePlus Seed chat, Seedance video, Seedream image, and Seed Speech TTS/ASR |
243| [`@tanstack/ai-fal`](https://tanstack.com/ai/latest/docs/adapters/fal) | fal.ai image, video, audio, speech, and transcription models |
244| [`@tanstack/ai-reactor`](https://tanstack.com/ai/latest/docs/adapters/reactor) | Reactor live world and video generation (Orbis, Happy Oyster, LingBot, Helios, FastH3) |
245| [`@tanstack/ai-worldlabs`](https://tanstack.com/ai/latest/docs/adapters/worldlabs) | World Labs Marble persistent 3D world generation |
246| [`@tanstack/ai-cloudflare`](https://tanstack.com/ai/latest/docs/adapters/cloudflare) | Cloudflare Workers AI chat, embeddings, image, speech, transcription, and AI Gateway |
247
248The adapter system is tree-shakeable by activity. Import `openaiText` for chat,
249`openaiImage` for images, `falVideo` for video, `geminiSpeech` for TTS, and so
250on.
251
252## Framework Packages
253
254| Package | What it provides |
255| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
256| [`@tanstack/ai-client`](https://tanstack.com/ai/latest/docs/api/ai-client) | Headless chat, realtime, and generation clients |
257| [`@tanstack/ai-react`](https://tanstack.com/ai/latest/docs/api/ai-react) | React hooks including `useChat`, `useRealtimeChat`, and generation hooks |
258| [`@tanstack/ai-solid`](https://tanstack.com/ai/latest/docs/api/ai-solid) | Solid hooks for chat and generations |
259| [`@tanstack/ai-vue`](https://tanstack.com/ai/latest/docs/api/ai-vue) | Vue composables for chat and generations |
260| [`@tanstack/ai-svelte`](https://tanstack.com/ai/latest/docs/api/ai-svelte) | Svelte 5 factories for chat and generations |
261| [`@tanstack/ai-preact`](https://tanstack.com/ai/latest/docs/api/ai-preact) | Preact hooks for chat |
262| `@tanstack/ai-react/ui`, `@tanstack/ai-solid/ui`, `@tanstack/ai-vue/ui`, `@tanstack/ai-svelte/ui` | Headless UI components for chat interfaces. |
263
264## Advanced Docs
265
266- [Middleware](https://tanstack.com/ai/latest/docs/advanced/middleware) - hook
267 into chat configuration, chunks, tool calls, usage, errors, and structured
268 outputs.
269- [OpenTelemetry](https://tanstack.com/ai/latest/docs/advanced/otel) - emit
270 vendor-neutral GenAI traces and metrics.
271- [Observability](https://tanstack.com/ai/latest/docs/advanced/observability) -
272 subscribe to typed TanStack AI events.
273- [Per-Model Type Safety](https://tanstack.com/ai/latest/docs/advanced/per-model-type-safety) -
274 narrow model options and content modalities to the selected model.
275- [Runtime Adapter Switching](https://tanstack.com/ai/latest/docs/advanced/runtime-adapter-switching) -
276 switch providers at runtime.
277- [Tree-Shaking](https://tanstack.com/ai/latest/docs/advanced/tree-shaking) -
278 ship only the activities and adapters you use.
279- [Agent Skills](https://tanstack.com/ai/latest/docs/getting-started/agent-skills) -
280 install TanStack AI skills into Claude Code, Cursor, GitHub Copilot, Codex,
281 and other coding agents. See [Agent Skills](#agent-skills) above for the
282 install commands.
283
284## Get Involved
285
286- Read the [docs](https://tanstack.com/ai).
287- Participate in [GitHub discussions](https://github.com/TanStack/ai/discussions).
288- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ).
289- See [CONTRIBUTING.md](https://github.com/TanStack/ai/blob/main/CONTRIBUTING.md)
290 for setup instructions.
291- [Become a sponsor](https://github.com/sponsors/tannerlinsley/).
292
293## Partners
294
295<table align="center">
296 <tr>
297 <td>
298 <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS">
299 <picture>
300 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-D643Zkrv.svg" />
301 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" />
302 <img src="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" height="40" alt="CodeRabbit" />
303 </picture>
304 </a>
305 </td>
306 <td>
307 <a href="https://www.cloudflare.com?utm_source=tanstack">
308 <picture>
309 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" />
310 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-6Ojsn8yh.svg" />
311 <img src="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" height="60" alt="Cloudflare" />
312 </picture>
313 </a>
314 </td>
315 </tr>
316</table>
317
318<div align="center">
319 <img src="https://raw.githubusercontent.com/TanStack/ai/main/media/partner_logo.svg" alt="AI and you?" height="65" />
320 <p>
321 We're looking for TanStack AI partners to join our mission. Partner with us
322 to push the boundaries of TanStack AI and build amazing things together.
323 </p>
324 <a href="mailto:partners@tanstack.com?subject=TanStack AI Partnership"><b>LET'S CHAT</b></a>
325</div>
326
327## Explore the TanStack Ecosystem
328
329- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> -
330 tooling for JS/TS packages
331- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> - reactive
332 sync client store
333- <a href="https://github.com/tanstack/devtools"><b>TanStack Devtools</b></a> -
334 unified devtools panel
335- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> -
336 type-safe form state
337- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> -
338 debouncing, throttling, batching
339- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> -
340 async state and caching
341- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> -
342 range and slider primitives
343- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> -
344 type-safe routing, caching, and URL state
345- <a href="https://github.com/tanstack/start"><b>TanStack Start</b></a> -
346 full-stack SSR and streaming
347- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> -
348 reactive data store
349- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> -
350 headless datagrids
351- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> -
352 virtualized rendering
353
354...and more at <a href="https://tanstack.com"><b>TanStack.com</b></a>.