Overview
The chat/ai subpath contains the AI utilities that ship with Chat SDK. Bots built on the AI SDK import from chat/ai; bots built on TanStack AI import the equivalent helpers from chat/ai/tanstack.
Add the optional peers if you don't already have them:
pnpm add ai zodWhat's included
| Page | What it gives you |
|---|---|
| AI SDK Tools | createChatTools and standalone tool factories that let an agent post messages, send DMs, react, edit, delete, and manage subscriptions across every adapter your Chat instance has registered. Write tools and getUser require approval by default, and presets limit which tools the agent gets. |
toAiMessages | Convert Chat SDK Message[] into the { role, content }[] shape expected by AI SDK calls. Handles role mapping, attachments, links, sorting, and optional per-message transforms. |
| TanStack AI | toTanStackMessages and createTanStackTools from chat/ai/tanstack: the same history conversion and tools, shaped for chat() from @tanstack/ai. No runtime dependency on @tanstack/ai. |
| Types | Reference for the types exported from chat/ai: agent message shapes, tool option contracts, presets, approval config, and the binding type that ties tools to your Chat instance. |
Typical flow
A Chat SDK bot wired to a tool-calling agent usually looks like this:
toAiMessagesconverts messages into an output compatible with AI SDK'sModelMessage[].createChatToolsgives the agent AI SDK tools for acting in chat, which you can narrow with presets and customize per tool.thread.post(stream)renders the streamed response back into the thread.
Using TanStack AI instead? The same flow works with toTanStackMessages and createTanStackTools; see TanStack AI for the chat() version of this example.
Backwards compatibility
toAiMessages and the related Ai* types are still re-exported from the top-level chat package so older bots keep working. Those re-exports are marked @deprecated in JSDoc, so your editor shows a hint pointing at chat/ai. To migrate, change the import:
Resources
- Human-in-the-Loop with Chat SDK and Workflow SDK: pause durable workflows on Slack approval cards using Chat SDK and Workflow SDK. The guide uses
createWebhookto suspend a workflow until a button click, with patterns for multi-stage approvals, timeouts via durable sleep, and approver validation.
See all guides and templates on the resources page.
Read more
AI SDK Tools
Let an AI agent post messages, send DMs, react, edit, and delete inside your workspace, with approval required for writes by default.
toAiMessages
Convert Chat SDK messages to AI SDK conversation format.
TanStack AI
Feed thread history into TanStack AI's chat() and give it Chat SDK tools, with no runtime dependency on @tanstack/ai.
Types
TypeScript types exported from the chat/ai subpath.