# TanStack AI

> A type-safe, provider-agnostic TypeScript SDK for streaming chat, tool calling, structured output, realtime voice and media generation

- Category: App Orchestration / App Frameworks
- Language: TypeScript
- Licence: MIT
- Repository: https://github.com/TanStack/ai
- Website: https://tanstack.com/ai
- Canonical page: https://ai-tldr.dev/tools/tanstack-ai/

## In short

TanStack AI is the AI SDK in the TanStack family — the same people behind TanStack Query, Router and Table. It is a type-safe, provider-agnostic TypeScript toolkit for building streaming chat, tool-calling agents, structured outputs, realtime voice, media generation and framework-native AI apps. It sits in the App Frameworks category of the App Orchestration tools and is open-source, written in TypeScript and licensed MIT.

## Overview

TanStack AI is the AI SDK in the TanStack family — the same people behind TanStack Query, Router and Table. It is a type-safe, provider-agnostic TypeScript toolkit for building streaming chat, tool-calling agents, structured outputs, realtime voice, media generation and framework-native AI apps. The design is deliberately modular: the library is built from composable activities and provider adapters, so you can install only chat and add image, audio, video, speech, transcription, summarization, realtime, Code Mode, devtools and framework bindings as the app grows.

Everything is typed end to end. A tool is declared once with toolDefinition() and then given a server or client implementation that shares the same input and output types. Structured output is backed by JSON Schema and works with Zod, ArkType, Valibot or plain JSON Schema. Messages carry typed parts — text, tool calls, reasoning — rather than opaque strings, and connection adapters are configurable, so the transport is not baked in. Framework clients ship for React, Solid, Vue, Svelte and Preact, plus a headless client for custom runtimes.

Because it is adapter-based, one provider or many is the same code: first-party packages cover OpenAI, Anthropic and others, and the OpenRouter adapter reaches many models behind one key. Beyond the basics it offers Code Mode agents, where the model writes and executes TypeScript in an isolated sandbox to orchestrate tools with loops, branches and parallel calls, and a devtools and observability pipeline for inspecting messages, tool calls, stream chunks, errors, usage and OpenTelemetry traces. The docs sum the package up as shipping the agent loop, provider adapters, durability, interrupts, sandboxes and tools, so it slots into an existing server, database and UI rather than replacing them. It is MIT-licensed.

## What it does

- Provider-agnostic adapters — write once, swap between OpenAI, Anthropic, OpenRouter and others without rewriting the app
- Type-safe tools: one toolDefinition() contract, then a server or client implementation sharing the same input and output types
- Structured output backed by JSON Schema, with Zod, ArkType, Valibot or raw JSON Schema
- Streaming chat with typed message parts (text, tool calls, reasoning) and configurable connection adapters
- Multimodal and generation activities: image, audio, video, speech, transcription and summarization through a shared generation-client pattern
- Realtime voice chat with provider adapters for realtime sessions and token minting
- Code Mode agents that let the model write and run TypeScript in an isolated sandbox to orchestrate tools
- Framework-native clients for React, Solid, Vue, Svelte and Preact, plus a headless client, and devtools with OpenTelemetry traces

## Getting started

Install the core package plus the provider and framework packages your app actually uses — nothing else is pulled in.

1. Install

   Core plus a provider is the minimum. Add the client and framework packages for a UI; OpenRouter is a good starting adapter if you want many models behind one key.

```bash
pnpm add @tanstack/ai @tanstack/ai-openai

# for a React chat UI
pnpm add @tanstack/ai @tanstack/ai-client @tanstack/ai-react @tanstack/ai-openai

# or many providers through one key
pnpm add @tanstack/ai @tanstack/ai-openrouter
```

2. Stream a chat response from a server route

   chat() returns a stream that a helper turns into a Server-Sent Events response, so any framework's route handler can return it directly.

```typescript
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'

export async function POST(request: Request) {
  const body = await request.json()

  const stream = chat({
    adapter: openaiText('gpt-5.2'),
    messages: body.messages,
  })

  return toServerSentEventsResponse(stream)
}
```

3. Define a tool once, implement it on the server

   The definition carries the input and output schemas; .server() attaches the implementation with those same types. A client implementation uses the identical contract.

```typescript
import { toolDefinition } from '@tanstack/ai'
import { z } from 'zod'

const getProducts = toolDefinition({
  name: 'getProducts',
  description: 'Search the product catalog',
  inputSchema: z.object({ query: z.string() }),
  outputSchema: z.array(
    z.object({
      id: z.string(),
      name: z.string(),
    }),
  ),
}).server(async ({ query }) => {
  return db.products.search(query)
})
```

4. Teach your coding agent the library

   TanStack ships user-level agent skills: install once and your agent maps a task to the right package, installs it, and loads that package's own SKILL.md. Inside a project, TanStack Intent wires the installed packages' skills into AGENTS.md or CLAUDE.md for the whole team.

```bash
# Claude Code and Cursor
/plugin marketplace add TanStack/ai
/plugin install tanstack-ai

# any agent
npx skills add TanStack/ai -g --skill tanstack-ai tanstack-ai-migration

# inside a project
npx @tanstack/intent@latest install
```

## When to use it

- Build a streaming chat UI in React, Vue, Svelte or Solid without hand-rolling SSE parsing and message state
- Keep one codebase across providers when you expect to swap or A/B models rather than commit to a single vendor
- Get typed tool calls and schema-validated structured output in a TypeScript app instead of parsing free-form JSON
- Add realtime voice, transcription or image generation to an existing app through the same client pattern as chat
