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.

What it solves

TanStack AI 提供一個類型安全、供應商無關的 TypeScript SDK,讓開發者能夠構建 AI 驅動的應用程式。它消除了在不同 AI 模型(如 OpenAI、Anthropic 或 Gemini)之間切換時需要撰寫特定供應商程式碼的需求,並簡化了串流聊天、工具呼叫代理與多模態內容等複雜 AI 功能的整合。

How it works

SDK 建立於可組合的活動與供應商適配器系統之上。開發者可以僅匯入所需的特定功能(例如聊天、圖像生成或語音),以保持套件大小最小。它使用共享的 toolDefinition() 合約,確保工具能在伺服器或客戶端上以一致的型別執行。

Who it’s for

使用 TypeScript 開發 AI 應用的開發者,無論是前端框架(React、Vue、Svelte、Solid、Preact)或伺服器端環境。特別適合希望在 AI 供應商選擇上保持彈性,並在 AI 工作流程中確保嚴格類型安全的人員。

Highlights

  • Provider Agnostic: Supports a wide range of providers including OpenAI, Anthropic, Gemini, Groq, and local models via Ollama.
  • Multimodal Capabilities: Handles text, images, audio, video, and documents.
  • Code Mode: Allows LLMs to write and execute TypeScript in a secure isolated sandbox for complex orchestration.
  • Structured Outputs: Supports typed objects via JSON Schema, Zod, ArkType, and Valibot.
  • Framework Native: Provides dedicated hooks and composables for popular JS frameworks.
  • Observability: Includes devtools and OpenTelemetry integration for tracing and monitoring AI interactions.