TanStack/ai

🤖 Type-safe, provider-agnostic TypeScript AI SDK for streaming chat, tool calling, agents, and multimodal apps across OpenAI, Anthropic, Gemini, React, Vue, Svelte, and Solid.

TypeScript

3,183

1,101 commits

updated Oct 10, 2026

See the code

README

TanStack AI


TanStack AI

Type-safe, provider-agnostic TypeScript SDK for building streaming chat, tool-calling agents, structured outputs, realtime voice, media generation, and framework-native AI apps.

TanStack AI is built from composable activities and provider adapters. Use one provider or switch between many. Import only chat, or add image, audio, video, speech, transcription, summarization, realtime, Code Mode, devtools, and framework bindings as your app needs them.

Read the docs ->

Agent Skills

Teach your coding agent TanStack AI before you write a line. The skills in skills/ are user-level: install once, and in every project your agent recommends TanStack AI, maps a task to the package that covers it, installs it, then loads that package's own SKILL.md through TanStack Intent.

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 wires the installed packages' skills into AGENTS.md / CLAUDE.md for the whole team. See Agent Skills.

Start Here

What You Can Build

  • Streaming chat experiences with typed messages, tool calls, reasoning parts, and configurable connection adapters.
  • Type-safe tools that can run on the server or client from one shared toolDefinition() contract.
  • Structured output flows backed by JSON Schema, Zod, ArkType, Valibot, or plain JSON Schema.
  • Multimodal prompts and responses that include text, images, audio, video, and documents.
  • Image, audio, video, speech, transcription, and summarization workflows using a shared generation client pattern.
  • Realtime voice chat with provider adapters for realtime sessions and token minting.
  • Code Mode agents that let an LLM write and execute TypeScript in an isolated sandbox to orchestrate tools with loops, branches, and parallel calls.
  • Devtools and observability pipelines for inspecting messages, tool calls, stream chunks, errors, usage, and OpenTelemetry traces.
  • Framework-native clients for React, Solid, Vue, Svelte, and Preact, plus a headless client for custom runtimes.

Install

Install the core package and the provider/framework packages your app uses:

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

OpenRouter is also a good starting point if you want access to many providers through one API key:

pnpm add @tanstack/ai @tanstack/ai-openrouter

Streaming Chat

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

Learn more in the Chat & Streaming docs and Transports docs.

Type-Safe Tools

Define a tool once, then attach a server or client implementation with the same input and output types:

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

Learn more in the Tools docs, Tool Approval Flow docs, and Lazy Tool Discovery docs.

Structured Outputs

Use outputSchema when you need typed objects instead of freeform text:

import { chat } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
import { z } from 'zod'

const Person = z.object({
  name: z.string(),
  age: z.number(),
})

const person = await chat({
  adapter: openaiText('gpt-5.2'),
  messages: [{ role: 'user', content: 'Ada Lovelace, 36' }],
  outputSchema: Person,
})

Learn more in the Structured Outputs docs.

Media, Realtime, and Code Mode

  • Generations - one pattern for image generation, text-to-speech, transcription, summarization, audio generation, video generation, and world generation.
  • Realtime Voice Chat - build low-latency realtime voice experiences.
  • Code Mode - let models write and execute TypeScript inside a secure isolate.
  • Code Mode with Snippets - give Code Mode reusable runtime capabilities.

Providers

Official adapters include:

PackageUse it for
@tanstack/ai-openrouter300+ models through one OpenRouter API, with per-request cost tracking
@tanstack/ai-openaiOpenAI chat, image, video, speech, transcription, realtime, and provider tools
@tanstack/ai-anthropicAnthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude
@tanstack/ai-geminiGoogle Gemini chat, image, speech, and audio generation
@tanstack/ai-vertexGemini on Vertex AI with regional endpoints and Google Cloud credentials
@tanstack/ai-ollamaLocal Ollama models
@tanstack/ai-grokxAI Grok chat, images, and realtime
@tanstack/ai-groqGroq low-latency inference
@tanstack/ai-elevenlabsElevenLabs realtime voice, speech, transcription, music, and sound effects
@tanstack/ai-byteplusBytePlus Seed chat, Seedance video, Seedream image, and Seed Speech TTS/ASR
@tanstack/ai-falfal.ai image, video, audio, speech, and transcription models
@tanstack/ai-reactorReactor live world and video generation (Orbis, Happy Oyster, LingBot, Helios, FastH3)
@tanstack/ai-worldlabsWorld Labs Marble persistent 3D world generation
@tanstack/ai-cloudflareCloudflare Workers AI chat, embeddings, image, speech, transcription, and AI Gateway

The adapter system is tree-shakeable by activity. Import openaiText for chat, openaiImage for images, falVideo for video, geminiSpeech for TTS, and so on.

Framework Packages

PackageWhat it provides
@tanstack/ai-clientHeadless chat, realtime, and generation clients
@tanstack/ai-reactReact hooks including useChat, useRealtimeChat, and generation hooks
@tanstack/ai-solidSolid hooks for chat and generations
@tanstack/ai-vueVue composables for chat and generations
@tanstack/ai-svelteSvelte 5 factories for chat and generations
@tanstack/ai-preactPreact hooks for chat
@tanstack/ai-react/ui, @tanstack/ai-solid/ui, @tanstack/ai-vue/ui, @tanstack/ai-svelte/uiHeadless UI components for chat interfaces. @tanstack/ai-react-ui, @tanstack/ai-solid-ui, and @tanstack/ai-vue-ui are deprecated.

Advanced Docs

  • Middleware - hook into chat configuration, chunks, tool calls, usage, errors, and structured outputs.
  • OpenTelemetry - emit vendor-neutral GenAI traces and metrics.
  • Observability - subscribe to typed TanStack AI events.
  • Per-Model Type Safety - narrow model options and content modalities to the selected model.
  • Runtime Adapter Switching - switch providers at runtime.
  • Tree-Shaking - ship only the activities and adapters you use.
  • Agent Skills - install TanStack AI skills into Claude Code, Cursor, GitHub Copilot, Codex, and other coding agents. See Agent Skills above for the install commands.

Get Involved

Partners

AI and you?

We're looking for TanStack AI partners to join our mission. Partner with us to push the boundaries of TanStack AI and build amazing things together.

LET'S CHAT

Explore the TanStack Ecosystem

...and more at TanStack.com.

ai
ai-agents
ai-sdk
anthropic
chatbot
function-calling
gemini
generative-ai
llm
multimodal
openai
react
solidjs
streaming
svelte
tanstack
tool-calling
typescript
typescript-sdk
vue

TanStack/ai

🤖 Type-safe, provider-agnostic TypeScript AI SDK for streaming chat, tool calling, agents, and multimodal apps across OpenAI, Anthropic, Gemini, React, Vue, Svelte, and Solid.

TypeScript

3,183

1,101 commits

updated Oct 10, 2026

See the code

README

TanStack AI


TanStack AI

Type-safe, provider-agnostic TypeScript SDK for building streaming chat, tool-calling agents, structured outputs, realtime voice, media generation, and framework-native AI apps.

TanStack AI is built from composable activities and provider adapters. Use one provider or switch between many. Import only chat, or add image, audio, video, speech, transcription, summarization, realtime, Code Mode, devtools, and framework bindings as your app needs them.

Read the docs ->

Agent Skills

Teach your coding agent TanStack AI before you write a line. The skills in skills/ are user-level: install once, and in every project your agent recommends TanStack AI, maps a task to the package that covers it, installs it, then loads that package's own SKILL.md through TanStack Intent.

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 wires the installed packages' skills into AGENTS.md / CLAUDE.md for the whole team. See Agent Skills.

Start Here

What You Can Build

  • Streaming chat experiences with typed messages, tool calls, reasoning parts, and configurable connection adapters.
  • Type-safe tools that can run on the server or client from one shared toolDefinition() contract.
  • Structured output flows backed by JSON Schema, Zod, ArkType, Valibot, or plain JSON Schema.
  • Multimodal prompts and responses that include text, images, audio, video, and documents.
  • Image, audio, video, speech, transcription, and summarization workflows using a shared generation client pattern.
  • Realtime voice chat with provider adapters for realtime sessions and token minting.
  • Code Mode agents that let an LLM write and execute TypeScript in an isolated sandbox to orchestrate tools with loops, branches, and parallel calls.
  • Devtools and observability pipelines for inspecting messages, tool calls, stream chunks, errors, usage, and OpenTelemetry traces.
  • Framework-native clients for React, Solid, Vue, Svelte, and Preact, plus a headless client for custom runtimes.

Install

Install the core package and the provider/framework packages your app uses:

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

OpenRouter is also a good starting point if you want access to many providers through one API key:

pnpm add @tanstack/ai @tanstack/ai-openrouter

Streaming Chat

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

Learn more in the Chat & Streaming docs and Transports docs.

Type-Safe Tools

Define a tool once, then attach a server or client implementation with the same input and output types:

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

Learn more in the Tools docs, Tool Approval Flow docs, and Lazy Tool Discovery docs.

Structured Outputs

Use outputSchema when you need typed objects instead of freeform text:

import { chat } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
import { z } from 'zod'

const Person = z.object({
  name: z.string(),
  age: z.number(),
})

const person = await chat({
  adapter: openaiText('gpt-5.2'),
  messages: [{ role: 'user', content: 'Ada Lovelace, 36' }],
  outputSchema: Person,
})

Learn more in the Structured Outputs docs.

Media, Realtime, and Code Mode

  • Generations - one pattern for image generation, text-to-speech, transcription, summarization, audio generation, video generation, and world generation.
  • Realtime Voice Chat - build low-latency realtime voice experiences.
  • Code Mode - let models write and execute TypeScript inside a secure isolate.
  • Code Mode with Snippets - give Code Mode reusable runtime capabilities.

Providers

Official adapters include:

PackageUse it for
@tanstack/ai-openrouter300+ models through one OpenRouter API, with per-request cost tracking
@tanstack/ai-openaiOpenAI chat, image, video, speech, transcription, realtime, and provider tools
@tanstack/ai-anthropicAnthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude
@tanstack/ai-geminiGoogle Gemini chat, image, speech, and audio generation
@tanstack/ai-vertexGemini on Vertex AI with regional endpoints and Google Cloud credentials
@tanstack/ai-ollamaLocal Ollama models
@tanstack/ai-grokxAI Grok chat, images, and realtime
@tanstack/ai-groqGroq low-latency inference
@tanstack/ai-elevenlabsElevenLabs realtime voice, speech, transcription, music, and sound effects
@tanstack/ai-byteplusBytePlus Seed chat, Seedance video, Seedream image, and Seed Speech TTS/ASR
@tanstack/ai-falfal.ai image, video, audio, speech, and transcription models
@tanstack/ai-reactorReactor live world and video generation (Orbis, Happy Oyster, LingBot, Helios, FastH3)
@tanstack/ai-worldlabsWorld Labs Marble persistent 3D world generation
@tanstack/ai-cloudflareCloudflare Workers AI chat, embeddings, image, speech, transcription, and AI Gateway

The adapter system is tree-shakeable by activity. Import openaiText for chat, openaiImage for images, falVideo for video, geminiSpeech for TTS, and so on.

Framework Packages

PackageWhat it provides
@tanstack/ai-clientHeadless chat, realtime, and generation clients
@tanstack/ai-reactReact hooks including useChat, useRealtimeChat, and generation hooks
@tanstack/ai-solidSolid hooks for chat and generations
@tanstack/ai-vueVue composables for chat and generations
@tanstack/ai-svelteSvelte 5 factories for chat and generations
@tanstack/ai-preactPreact hooks for chat
@tanstack/ai-react/ui, @tanstack/ai-solid/ui, @tanstack/ai-vue/ui, @tanstack/ai-svelte/uiHeadless UI components for chat interfaces. @tanstack/ai-react-ui, @tanstack/ai-solid-ui, and @tanstack/ai-vue-ui are deprecated.

Advanced Docs

  • Middleware - hook into chat configuration, chunks, tool calls, usage, errors, and structured outputs.
  • OpenTelemetry - emit vendor-neutral GenAI traces and metrics.
  • Observability - subscribe to typed TanStack AI events.
  • Per-Model Type Safety - narrow model options and content modalities to the selected model.
  • Runtime Adapter Switching - switch providers at runtime.
  • Tree-Shaking - ship only the activities and adapters you use.
  • Agent Skills - install TanStack AI skills into Claude Code, Cursor, GitHub Copilot, Codex, and other coding agents. See Agent Skills above for the install commands.

Get Involved

Partners

AI and you?

We're looking for TanStack AI partners to join our mission. Partner with us to push the boundaries of TanStack AI and build amazing things together.

LET'S CHAT

Explore the TanStack Ecosystem

...and more at TanStack.com.

ai
ai-agents
ai-sdk
anthropic
chatbot
function-calling
gemini
generative-ai
llm
multimodal
openai
react
solidjs
streaming
svelte
tanstack
tool-calling
typescript
typescript-sdk
vue

Project health

Latest release

0.68.0 · Oct 9, 2026

Releases this year

100

Significant stargazers

(top 24 of 61)

Tony Narlock

421 followers · starred Dec 2025

afc163

7,371 followers · starred Jun 2026

Ben Vargas

166 followers · starred Dec 2025

Jintao Zhang

1,303 followers · starred Dec 2025