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.