0
Fork 0
mirror of https://github.com/TanStack/ai.git synced 2026-11-16 19:38:41 +00:00
🤖 SDK that enhances your applications with AI capabilities
  • TypeScript 99.8%
  • JavaScript 0.1%
Find a file
Tom Beckenham 4bd213f18e
Merge pull request #2168 from refs/pull/2168/head
fix(ci): skip Chromium install when coverage measures the merge base
History 2026-11-16 14:31:44 +01:00
.agent Merge pull request #100002 from feat/ai-effect 2026-11-06 18:18:59 +01:00
.agents/skills refactor!: remove every deprecated API and release all packages as 1.0.0 (#1840) 2026-10-22 15:34:59 +11:00
.changeset fix(ci): upgrade Playwright so Chromium installs on Ubuntu 26.04 (#2166) 2026-11-16 21:11:15 +11:00
.claude refactor!: remove every deprecated API and release all packages as 1.0.0 (#1840) 2026-10-22 15:34:59 +11:00
.claude-plugin feat: ship repo-level agent skills for TanStack AI capability discovery (#1348) 2026-09-09 07:22:11 +02:00
.cursor-plugin feat: ship repo-level agent skills for TanStack AI capability discovery (#1348) 2026-09-09 07:22:11 +02:00
.github Merge pull request #2168 from refs/pull/2168/head 2026-11-16 14:31:44 +01:00
.grok/skills refactor!: remove every deprecated API and release all packages as 1.0.0 (#1840) 2026-10-22 15:34:59 +11:00
.source/workflows Merge pull request #2128 from alem/source-package-previews 2026-11-10 17:27:44 +01:00
.vscode chore: migrate toolchain to oxc + TypeScript 7 + vite 8 (#949) 2026-07-21 15:00:16 +02:00
_artifacts chore: remove stale PHP and Python packages (#643) 2026-05-26 10:06:29 +02:00
agent-scripts/ai-review fix(ci): run the AI review script with node instead of tsx (#1712) 2026-10-12 13:48:43 +02:00
codemods chore(deps): update build & test tooling (#2161) 2026-11-16 12:04:17 +00:00
docs fix(ai): run onAbort when a chat() consumer stops iterating (#2098) 2026-11-13 06:51:28 +07:00
examples chore(deps): update build & test tooling (#2161) 2026-11-16 12:04:17 +00:00
media docs: use orange award badge (#1046) 2026-08-03 14:57:58 +02:00
packages chore(deps): update build & test tooling (#2161) 2026-11-16 12:04:17 +00:00
patches fix: patch changesets to prevent major bumps from peer deps (#361) 2026-03-10 21:16:25 +01:00
scripts feat(ai-gemini): add Gemini Omni 1.2 Flash (#2066) 2026-11-06 06:30:22 +01:00
skills feat(ai-neon, openai-base): add the Neon AI Gateway adapter (#1851) 2026-10-22 14:14:53 +00:00
testing chore(deps): update build & test tooling (#2161) 2026-11-16 12:04:17 +00:00
tools/workspace-plugin chore(deps): update build & test tooling (#2161) 2026-11-16 12:04:17 +00:00
.coderabbit.yaml docs: clarify contribution guidelines (#1237) 2026-08-25 10:05:06 +02:00
.cursorignore chore: migrating to tanstack config (#30) 2025-11-27 12:37:42 -08:00
.editorconfig chore: monorepo setup audit (build, tsconfig, types, docs) (#572) 2026-05-19 15:06:18 +02:00
.gitattributes ci: add more shared TanStack config (#49) 2025-11-29 15:19:41 +11:00
.gitignore test(ai-persistence): check persistence adapter skills (#1921) 2026-10-27 11:25:47 +00:00
.npmrc ci: add more shared TanStack config (#49) 2025-11-29 15:19:41 +11:00
.nvmrc chore: bump pinned Node to 24.22.1 (#1914) 2026-10-30 16:08:14 +11:00
.oxfmtrc.json build(adapters): remove unused zod peer dependencies (#1253) 2026-08-27 10:21:32 +00:00
.oxlintrc.json perf(providers): call provider APIs with fetch instead of the SDK runtime (#1973) 2026-11-04 15:10:41 +01:00
AGENTS.md chore: document Node 24.8.0 and pnpm 11.9.0 as the toolchain (#1711) 2026-10-12 11:34:10 +00:00
CHANGELOG.md chore: remove stale PHP and Python packages (#643) 2026-05-26 10:06:29 +02:00
CLAUDE.md Merge pull request #2047 from refs/pull/2047/head 2026-11-06 11:23:54 +01:00
CODE_OF_CONDUCT.md chore: migrating to tanstack config (#30) 2025-11-27 12:37:42 -08:00
CONTRIBUTING.md chore: bump pinned Node to 24.22.1 (#1914) 2026-10-30 16:08:14 +11:00
kiira.config.ts docs: type-check the package READMEs and fix their broken examples (#1981) 2026-11-04 15:29:28 +01:00
knip.json Merge pull request #100001 from ci/source-workflows 2026-11-10 10:54:29 +01:00
LICENSE chore: migrating to tanstack config (#30) 2025-11-27 12:37:42 -08:00
nx.json docs: type-check the package READMEs and fix their broken examples (#1981) 2026-11-04 15:29:28 +01:00
package.json chore(deps): update build & test tooling (#2161) 2026-11-16 12:04:17 +00:00
pnpm-lock.yaml chore(deps): update build & test tooling (#2161) 2026-11-16 12:04:17 +00:00
pnpm-workspace.yaml Merge pull request #2047 from refs/pull/2047/head 2026-11-06 11:23:54 +01:00
README.md docs: type-check the package READMEs and fix their broken examples (#1981) 2026-11-04 15:29:28 +01:00
tsconfig.base.json chore: migrate toolchain to oxc + TypeScript 7 + vite 8 (#949) 2026-07-21 15:00:16 +02:00
tsconfig.docs.json test(ai-persistence): check persistence adapter skills (#1921) 2026-10-27 11:25:47 +00:00
tsconfig.json fix(maintainer): add .ts extensions so node can load the sweep (#1943) 2026-10-29 10:44:09 +01:00
typedoc.json docs: remove duplicate page headings (#1364) 2026-09-17 11:18:31 +02:00

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,
    threadId: body.threadId,
  })

  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'
import { db } from './db'

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' }],
  threadId: 'thread-1',
  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:

Package Use it for
@tanstack/ai-openrouter 300+ models through one OpenRouter API, with per-request cost tracking
@tanstack/ai-openai OpenAI chat, image, video, speech, transcription, realtime, and provider tools
@tanstack/ai-anthropic Anthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude
@tanstack/ai-gemini Google Gemini chat, image, speech, and audio generation
@tanstack/ai-vertex Gemini on Vertex AI with regional endpoints and Google Cloud credentials
@tanstack/ai-ollama Local Ollama models
@tanstack/ai-grok xAI Grok chat, images, and realtime
@tanstack/ai-groq Groq low-latency inference
@tanstack/ai-elevenlabs ElevenLabs realtime voice, speech, transcription, music, and sound effects
@tanstack/ai-byteplus BytePlus Seed chat, Seedance video, Seedream image, and Seed Speech TTS/ASR
@tanstack/ai-fal fal.ai image, video, audio, speech, and transcription models
@tanstack/ai-reactor Reactor live world and video generation (Orbis, Happy Oyster, LingBot, Helios, FastH3)
@tanstack/ai-worldlabs World Labs Marble persistent 3D world generation
@tanstack/ai-cloudflare Cloudflare Workers AI chat, embeddings, image, speech, transcription, and AI Gateway
@tanstack/ai-neon Neon AI Gateway chat and embeddings for Claude, GPT, Gemini, and open models

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

Package What it provides
@tanstack/ai-client Headless chat, realtime, and generation clients
@tanstack/ai-react React hooks including useChat, useRealtimeChat, and generation hooks
@tanstack/ai-solid Solid hooks for chat and generations
@tanstack/ai-vue Vue composables for chat and generations
@tanstack/ai-svelte Svelte 5 factories for chat and generations
@tanstack/ai-preact Preact hooks for chat
@tanstack/ai-react/ui, @tanstack/ai-solid/ui, @tanstack/ai-vue/ui, @tanstack/ai-svelte/ui Headless UI components for chat interfaces.

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

CodeRabbit Cloudflare
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.