TanStack AI is a TypeScript SDK for streaming chat, tool calls, and media generation. Swap the provider or the UI framework without rewriting the call.
TanStack 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.
Start here: Quick Start. You get a streaming chat in about 5 minutes.
Later, when you need them:
A chat has two halves:
Tools 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.
import { chat, toolDefinition } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
import { z } from 'zod'
const products = [
{ id: '1', name: 'Blue mug' },
{ id: '2', name: 'Red mug' },
]
const getProductsDef = toolDefinition({
name: 'getProducts',
description: 'Search for products by query',
inputSchema: z.object({ query: z.string() }),
outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
})
const getProducts = getProductsDef.server(async ({ query }) =>
products.filter((product) => product.name.toLowerCase().includes(query)),
)
const stream = chat({
adapter: openaiText('gpt-6.1-sol'),
messages: [{ role: 'user', content: 'Find mugs' }],
threadId: 'thread-1',
tools: [getProducts],
})Each tutorial builds one small app from start to finish:
The core works in any JavaScript runtime. These hosts are common:
| Host | Notes |
|---|---|
| TanStack Start | React Start or Solid Start. |
| Next.js | API routes and App Router. |
| React Router v7 | Loaders and actions. |
| Remix 3 | Controllers return SSE. Call createChat in a clientEntry island. |
| Express | Node.js server. See Quick Start: Server Only. |
| React Native / Expo | useChat with an absolute server URL and an XHR transport. See Quick Start: React Native. |
| Package | What it does |
|---|---|
| @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. |
| @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. |
| @tanstack/ai-react | useChat for React, with approvals and typed messages through InferChatMessages. |
| @tanstack/ai-solid | useChat for Solid, with the same features as React. |
| @tanstack/ai-octane | useChat for Octane, with the same hook names as @tanstack/ai-react. The Octane plugin compiles it from .tsrx source. |
Vue, Svelte, Preact, Angular, and Remix have their own packages too. See the API reference for each one.
Each adapter is its own package. Install only the ones you use.
| Package | Provider |
|---|---|
| @tanstack/ai-openrouter | OpenRouter. 300+ models with one API key. A good first pick. |
| @tanstack/ai-openai | OpenAI (GPT models). |
| @tanstack/ai-anthropic | Anthropic (Claude). |
| @tanstack/ai-gemini | Google Gemini. |
| @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. |
| @tanstack/ai-ollama | Ollama (local models). |
| @tanstack/ai-groq | Groq. |
| @tanstack/ai-grok | xAI Grok. |
| @tanstack/ai-bedrock | Amazon Bedrock (Claude, Nova, Llama, and more through AWS). |
| @tanstack/ai-byteplus | BytePlus (Seed chat, Seedance video, Seedream image, Seed Speech). |
| @tanstack/ai-fal | fal (image and video generation). |
| @tanstack/ai-reactor | Reactor (live world and video generation: Orbis, Happy Oyster, LingBot, Helios, FastH3). |
| @tanstack/ai-worldlabs | World Labs Marble (persistent 3D world generation). |
| @tanstack/ai-llmgateway | LLM Gateway. Hundreds of models through one OpenAI-compatible endpoint. You can host it yourself. |
| @tanstack/ai-cloudflare | Cloudflare Workers AI (chat, embeddings, image, speech, transcription, evaluate) and AI Gateway routing. |
| @tanstack/ai-neon | Neon AI Gateway (Claude, GPT, Gemini, and open models, plus embeddings, through one Neon credential). |
| @tanstack/ai-typesafe | TypeSafe Jev (typed evaluate decisions). |
| @tanstack/ai-ollaya | Local Ollaya laya models for typed evaluate decisions. No API key. |
| @tanstack/ai-lovable | Lovable AI Gateway (Google and OpenAI chat, image, video, embeddings, and speech through one project key). |
The Adapters section of the sidebar has a page for each provider.