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

README.md

355 lines16.4 KB

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)
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| [`@tanstack/ai-neon`](https://tanstack.com/ai/latest/docs/adapters/neon) | Neon AI Gateway chat and embeddings for Claude, GPT, Gemini, and open models |
248​
249The adapter system is tree-shakeable by activity. Import `openaiText` for chat,
250`openaiImage` for images, `falVideo` for video, `geminiSpeech` for TTS, and so
251on.
252​
253## Framework Packages
254​
255| Package | What it provides |
256| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
257| [`@tanstack/ai-client`](https://tanstack.com/ai/latest/docs/api/ai-client) | Headless chat, realtime, and generation clients |
258| [`@tanstack/ai-react`](https://tanstack.com/ai/latest/docs/api/ai-react) | React hooks including `useChat`, `useRealtimeChat`, and generation hooks |
259| [`@tanstack/ai-solid`](https://tanstack.com/ai/latest/docs/api/ai-solid) | Solid hooks for chat and generations |
260| [`@tanstack/ai-vue`](https://tanstack.com/ai/latest/docs/api/ai-vue) | Vue composables for chat and generations |
261| [`@tanstack/ai-svelte`](https://tanstack.com/ai/latest/docs/api/ai-svelte) | Svelte 5 factories for chat and generations |
262| [`@tanstack/ai-preact`](https://tanstack.com/ai/latest/docs/api/ai-preact) | Preact hooks for chat |
263| `@tanstack/ai-react/ui`, `@tanstack/ai-solid/ui`, `@tanstack/ai-vue/ui`, `@tanstack/ai-svelte/ui` | Headless UI components for chat interfaces. |
264​
265## Advanced Docs
266​
267- [Middleware](https://tanstack.com/ai/latest/docs/advanced/middleware) - hook
268 into chat configuration, chunks, tool calls, usage, errors, and structured
269 outputs.
270- [OpenTelemetry](https://tanstack.com/ai/latest/docs/advanced/otel) - emit
271 vendor-neutral GenAI traces and metrics.
272- [Observability](https://tanstack.com/ai/latest/docs/advanced/observability) -
273 subscribe to typed TanStack AI events.
274- [Per-Model Type Safety](https://tanstack.com/ai/latest/docs/advanced/per-model-type-safety) -
275 narrow model options and content modalities to the selected model.
276- [Runtime Adapter Switching](https://tanstack.com/ai/latest/docs/advanced/runtime-adapter-switching) -
277 switch providers at runtime.
278- [Tree-Shaking](https://tanstack.com/ai/latest/docs/advanced/tree-shaking) -
279 ship only the activities and adapters you use.
280- [Agent Skills](https://tanstack.com/ai/latest/docs/getting-started/agent-skills) -
281 install TanStack AI skills into Claude Code, Cursor, GitHub Copilot, Codex,
282 and other coding agents. See [Agent Skills](#agent-skills) above for the
283 install commands.
284​
285## Get Involved
286​
287- Read the [docs](https://tanstack.com/ai).
288- Participate in [GitHub discussions](https://github.com/TanStack/ai/discussions).
289- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ).
290- See [CONTRIBUTING.md](https://github.com/TanStack/ai/blob/main/CONTRIBUTING.md)
291 for setup instructions.
292- [Become a sponsor](https://github.com/sponsors/tannerlinsley/).
293​
294## Partners
295​
296<table align="center">
297 <tr>
298 <td>
299 <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS">
300 <picture>
301 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-D643Zkrv.svg" />
302 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" />
303 <img src="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" height="40" alt="CodeRabbit" />
304 </picture>
305 </a>
306 </td>
307 <td>
308 <a href="https://www.cloudflare.com?utm_source=tanstack">
309 <picture>
310 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" />
311 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-6Ojsn8yh.svg" />
312 <img src="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" height="60" alt="Cloudflare" />
313 </picture>
314 </a>
315 </td>
316 </tr>
317</table>
318​
319<div align="center">
320 <img src="https://raw.githubusercontent.com/TanStack/ai/main/media/partner_logo.svg" alt="AI and you?" height="65" />
321 <p>
322 We're looking for TanStack AI partners to join our mission. Partner with us
323 to push the boundaries of TanStack AI and build amazing things together.
324 </p>
325 <a href="mailto:partners@tanstack.com?subject=TanStack AI Partnership"><b>LET'S CHAT</b></a>
326</div>
327​
328## Explore the TanStack Ecosystem
329​
330- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> -
331 tooling for JS/TS packages
332- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> - reactive
333 sync client store
334- <a href="https://github.com/tanstack/devtools"><b>TanStack Devtools</b></a> -
335 unified devtools panel
336- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> -
337 type-safe form state
338- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> -
339 debouncing, throttling, batching
340- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> -
341 async state and caching
342- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> -
343 range and slider primitives
344- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> -
345 type-safe routing, caching, and URL state
346- <a href="https://github.com/tanstack/start"><b>TanStack Start</b></a> -
347 full-stack SSR and streaming
348- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> -
349 reactive data store
350- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> -
351 headless datagrids
352- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> -
353 virtualized rendering
354​
355...and more at <a href="https://tanstack.com"><b>TanStack.com</b></a>.