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

overview.md

104 lines3.9 KB

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