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

overview.md

153 lines6.9 KB

1---
2title: Overview
3id: overview
4order: 1
5description: "TanStack AI is a type-safe, provider-agnostic TypeScript SDK for building streaming chat, tool calling, and AI features that work across any 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 lightweight, type-safe SDK for building production-ready AI experiences. Its framework-agnostic core provides type-safe tool/function calling, streaming responses, and first-class React and Solid integrations, with adapters for multiple LLM providers — enabling predictable, composable, and testable AI features across any stack.
18​
19Build a streaming React chat in [Basic Chat](../tutorials/basic-chat). The key stays in the tab.
20​
21Serve a tool, a resource, and a prompt in [Build an MCP Server](../tutorials/mcp-server).
22​
23Generate an image from a prompt in [Generate Image](../tutorials/generate-image).
24​
25Stream a typed table from `chat({ outputSchema })` in [Streaming Structured Table](../tutorials/streaming-structured-table).
26​
27Add three named agents (researcher, SEO, and writer) to a blog-writing chat in [Subagents](../tutorials/subagents).
28​
29## Key Features
30​
31- ✅ **Type-Safe** - Full TypeScript support with Zod schema inference
32- ✅ **Streaming** - Built-in streaming support for real-time responses
33- ✅ **Isomorphic Tools** - Define once with `toolDefinition()`, implement with `.server()` or `.client()`
34- ✅ **Framework Agnostic** - Core library works anywhere
35- ✅ **Multiple Providers** - OpenRouter, OpenAI, Anthropic, Gemini, Ollama, and more
36- ✅ **Typed Decisions** - Ask `choice`, `score`, and `boolean` questions with `decide()`
37- ✅ **Approval Flow** - Built-in support for tool approval workflows
38- ✅ **Automatic Execution** - Both server and client tools execute automatically
39​
40Users can paste their own provider API keys in the browser. See [Bring Your Own Key](../advanced/byok).
41​
42## Framework Agnostic
43​
44The framework-agnostic core of TanStack AI provides the building blocks for creating AI experiences in any environment, including:
45​
46- **Next.js** - API routes and App Router
47- **TanStack Start** - React Start or Solid Start (recommended!)
48- **Remix 3** - Controllers return SSE. Call `createChat` in a `clientEntry` island
49- **React Native / Expo** - Native chat screens with `useChat`, absolute server URLs, and XHR streaming transports
50- **Express** - Node.js server
51- **React Router v7** - Loaders and actions
52​
53TanStack AI lets you define a tool once and provide environment-specific implementations. Using `toolDefinition()` to declare the tool's input/output types and the server behavior with `.server()` (or a client implementation with `.client()`). These isomorphic tools can be invoked from the AI runtime regardless of framework.
54​
55```typescript
56import { chat, toolDefinition } from '@tanstack/ai'
57import { openaiText } from '@tanstack/ai-openai'
58import { z } from 'zod'
59import { db } from './db'
60​
61// Define a tool
62const getProductsDef = toolDefinition({
63 name: 'getProducts',
64 description: 'Search for products by query',
65 inputSchema: z.object({ query: z.string() }),
66 outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
67})
68​
69// Create server implementation
70const getProducts = getProductsDef.server(async ({ query }) => {
71 return await db.products.search(query)
72})
73​
74// Use in AI chat
75chat({
76 adapter: openaiText('gpt-5.2'),
77 messages: [{ role: 'user', content: 'Find products' }],
78 tools: [getProducts]
79})
80```
81​
82## Core Packages
83​
84The TanStack AI ecosystem consists of several packages:
85​
86### `@tanstack/ai`
87The core AI library that provides:
88- AI adapter interface for connecting to LLM providers
89- Chat completion and streaming
90- Isomorphic tool/function calling system
91- Agent loop strategies
92- Type-safe tool definitions with `toolDefinition()`
93- Type-safe Model Options based on adapter & model selection
94- Type-safe content modalities (text, image, audio, video, document) based on model capabilities
95​
96### `@tanstack/ai-client`
97A framework-agnostic headless client for managing chat state:
98- Message management with full type safety
99- Streaming support
100- Connection adapters (SSE, HTTP stream, custom)
101- Automatic tool execution (server and client)
102- Tool approval flow handling
103​
104### `@tanstack/ai-react`
105React hooks for TanStack AI:
106- `useChat` hook for chat interfaces
107- Automatic state management
108- Tool approval flow support
109- Type-safe message handling with `InferChatMessages`
110​
111### `@tanstack/ai-solid`
112Solid hooks for TanStack AI:
113- `useChat` hook for chat interfaces
114- Automatic state management
115- Tool approval flow support
116- Type-safe message handling with `InferChatMessages`
117​
118### `@tanstack/ai-octane`
119Octane hooks for TanStack AI:
120- `useChat` hook for chat interfaces
121- Same hook names as `@tanstack/ai-react`
122- Compiled by the Octane plugin from `.tsrx` source
123​
124## Adapters
125​
126With the help of adapters, TanStack AI can connect to various LLM providers. Available adapters include:
127​
128- **@tanstack/ai-openrouter** - OpenRouter (300+ models via a single API key — recommended)
129- **@tanstack/ai-openai** - OpenAI (GPT series)
130- **@tanstack/ai-anthropic** - Anthropic (Claude)
131- **@tanstack/ai-gemini** - Google Gemini
132- **@tanstack/ai-vertex** - Gemini on Google Vertex AI. Claude, Grok, and Mistral on Vertex live on `@tanstack/ai-anthropic/vertex`, `@tanstack/ai-grok/vertex`, and `@tanstack/ai-mistral/vertex`.
133- **@tanstack/ai-ollama** - Ollama (local models)
134- **@tanstack/ai-groq** - Groq
135- **@tanstack/ai-grok** - xAI Grok
136- **@tanstack/ai-bedrock** - Amazon Bedrock (Claude, Nova, Llama, and more via AWS)
137- **@tanstack/ai-byteplus** - BytePlus (Seed chat, Seedance video, Seedream image, Seed Speech)
138- **@tanstack/ai-fal** - fal (image & video generation)
139- **@tanstack/ai-reactor** - Reactor (live world and video generation: Orbis, Happy Oyster, LingBot, Helios, FastH3)
140- **@tanstack/ai-worldlabs** - World Labs Marble (persistent 3D world generation)
141- **@tanstack/ai-llmgateway** - LLM Gateway (hundreds of models via one OpenAI-compatible endpoint, self-hostable)
142- **@tanstack/ai-cloudflare** - Cloudflare Workers AI (chat, embeddings, image, speech, transcription, evaluate) and AI Gateway routing
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 via one project key)
146​
147## Next Steps
148​
149- [Quick Start](./quick-start) - Add streaming chat. Pick your framework at the top of the page.
150- [Quick Start: React Native](./quick-start-react-native) - Add mobile chat with Expo and a server-owned provider boundary
151- [Evaluate](../evaluate/evaluate) - Ask typed questions and branch on the answers
152- [Tools Guide](../tools/tools) - Learn about the isomorphic tool system
153- [API Reference](../api/ai) - Explore the full API