█

AI/TLDR

TanStack AI

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

App FrameworksOpen source
Language
TypeScript
License
MIT
$pnpm add @tanstack/ai @tanstack/ai-openai

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.

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.

bashbash
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

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.

typescripttypescript
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)
}

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.

typescripttypescript
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)
})

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.

bashbash
# 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

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

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

How TanStack AI compares

TanStack AI alongside other open-source app frameworks tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
LangChain★ 148kA widely used Python and JavaScript framework for building LLM applications by composing models, prompts, tools, retrievers, and memory into chains.
LlamaIndex★ 52.6kA data framework for connecting language models to your own documents and data sources, with built-in agent and retrieval (RAG) tooling.
Haystack★ 26.8kAn orchestration framework from deepset for building modular LLM pipelines and agents for search, RAG, and question answering.
Jina★ 21.9kJina-serve is a Python framework for building, scaling, and deploying AI services and multi-step pipelines that communicate over gRPC, HTTP, and WebSockets.
RocketRide★ 17.7kMIT-licensed AI pipeline builder and multithreaded C++ runtime: design .pipe JSON workflows visually in VS Code from 100+ nodes (LLMs, vector DBs, OCR, agents), then call them via Python/TypeScript SDKs or MCP.
LLM★ 12.6kSimon Willison's plugin-extensible CLI and Python library for prompting remote and local models, logging every prompt and response to SQLite, and generating embeddings.
Prompt Flow★ 11.3kMicrosoft's toolkit for building LLM apps as executable flows that link prompts, Python code, and tools, with tracing, batch evaluation, and deployment.
TanStack AI★ 3.2kA type-safe, provider-agnostic TypeScript SDK for streaming chat, tool calling, structured output, realtime voice and media generation