TanStack 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.
The framework-agnostic core of TanStack AI provides the building blocks for creating AI experiences in any environment, including:
TanStack 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.
import { toolDefinition } from '@tanstack/ai'
// Define a tool
const getProductsDef = toolDefinition({
name: 'getProducts',
inputSchema: z.object({ query: z.string() }),
outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
})
// Create server implementation
const getProducts = getProductsDef.server(async ({ query }) => {
return await db.products.search(query)
})
// Use in AI chat
chat({ tools: [getProducts] })
import { toolDefinition } from '@tanstack/ai'
// Define a tool
const getProductsDef = toolDefinition({
name: 'getProducts',
inputSchema: z.object({ query: z.string() }),
outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
})
// Create server implementation
const getProducts = getProductsDef.server(async ({ query }) => {
return await db.products.search(query)
})
// Use in AI chat
chat({ tools: [getProducts] })
The TanStack AI ecosystem consists of several packages:
The core AI library that provides:
A framework-agnostic headless client for managing chat state:
React hooks for TanStack AI:
Solid hooks for TanStack AI:
With the help of adapters, TanStack AI can connect to various LLM providers. Available adapters include:
