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

overview.md

118 lines4.4 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​
19## Key Features
20​
21- ✅ **Type-Safe** - Full TypeScript support with Zod schema inference
22- ✅ **Streaming** - Built-in streaming support for real-time responses
23- ✅ **Isomorphic Tools** - Define once with `toolDefinition()`, implement with `.server()` or `.client()`
24- ✅ **Framework Agnostic** - Core library works anywhere
25- ✅ **Multiple Providers** - OpenRouter, OpenAI, Anthropic, Gemini, Ollama, and more
26- ✅ **Approval Flow** - Built-in support for tool approval workflows
27- ✅ **Automatic Execution** - Both server and client tools execute automatically
28​
29## Framework Agnostic
30​
31The framework-agnostic core of TanStack AI provides the building blocks for creating AI experiences in any environment, including:
32​
33- **Next.js** - API routes and App Router
34- **TanStack Start** - React Start or Solid Start (recommended!)
35- **Express** - Node.js server
36- **React Router v7** - Loaders and actions
37​
38TanStack 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.
39​
40```typescript
41import { chat } from '@tanstack/ai'
42import { toolDefinition } from '@tanstack/ai'
43import { openaiText } from '@tanstack/ai-openai'
44​
45// Define a tool
46const getProductsDef = toolDefinition({
47 name: 'getProducts',
48 inputSchema: z.object({ query: z.string() }),
49 outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
50})
51​
52// Create server implementation
53const getProducts = getProductsDef.server(async ({ query }) => {
54 return await db.products.search(query)
55})
56​
57// Use in AI chat
58chat({
59 adapter: openaiText('gpt-5.2'),
60 messages: [{ role: 'user', content: 'Find products' }],
61 tools: [getProducts]
62})
63```
64​
65## Core Packages
66​
67The TanStack AI ecosystem consists of several packages:
68​
69### `@tanstack/ai`
70The core AI library that provides:
71- AI adapter interface for connecting to LLM providers
72- Chat completion and streaming
73- Isomorphic tool/function calling system
74- Agent loop strategies
75- Type-safe tool definitions with `toolDefinition()`
76- Type-safe Model Options based on adapter & model selection
77- Type-safe content modalities (text, image, audio, video, document) based on model capabilities
78​
79### `@tanstack/ai-client`
80A framework-agnostic headless client for managing chat state:
81- Message management with full type safety
82- Streaming support
83- Connection adapters (SSE, HTTP stream, custom)
84- Automatic tool execution (server and client)
85- Tool approval flow handling
86​
87### `@tanstack/ai-react`
88React hooks for TanStack AI:
89- `useChat` hook for chat interfaces
90- Automatic state management
91- Tool approval flow support
92- Type-safe message handling with `InferChatMessages`
93​
94### `@tanstack/ai-solid`
95Solid hooks for TanStack AI:
96- `useChat` hook for chat interfaces
97- Automatic state management
98- Tool approval flow support
99- Type-safe message handling with `InferChatMessages`
100​
101## Adapters
102​
103With the help of adapters, TanStack AI can connect to various LLM providers. Available adapters include:
104​
105- **@tanstack/ai-openrouter** - OpenRouter (300+ models via a single API key — recommended)
106- **@tanstack/ai-openai** - OpenAI (GPT series)
107- **@tanstack/ai-anthropic** - Anthropic (Claude)
108- **@tanstack/ai-gemini** - Google Gemini
109- **@tanstack/ai-ollama** - Ollama (local models)
110- **@tanstack/ai-groq** - Groq
111- **@tanstack/ai-grok** - xAI Grok
112- **@tanstack/ai-fal** - fal (image & video generation)
113​
114## Next Steps
115​
116- [Quick Start Guide](./quick-start) - Get up and running in minutes
117- [Tools Guide](../tools/tools) - Learn about the isomorphic tool system
118- [API Reference](../api/ai) - Explore the full API