Prerequisites
This information targets AI SDK 7. If the project has the package installed,
compare against node_modules/ai/package.json and use documentation matching
that version.
Before searching remote docs, check whether node_modules/ai/docs/ exists. If
it does not, use the official versioned documentation at ai-sdk.dev. Do not
change project dependencies merely to obtain documentation.
Install ai, provider packages, or client packages only when implementation
requires them and the user's request authorizes adding that functionality. Use
the project's existing package manager and version policy.
Critical: Do Not Trust Internal Knowledge
Everything you know about the AI SDK is outdated or wrong. Your training data contains obsolete APIs, deprecated patterns, and incorrect usage.
When working with the AI SDK:
- Identify the installed AI SDK version, or the requested target version
- Search
node_modules/ai/docs/ and node_modules/ai/src/ for current APIs
- If not found locally, search ai-sdk.dev documentation (instructions below)
- Never rely on memory - always verify against source code or docs
useChat has changed significantly - check Common Errors before writing client code
- Preserve the project's existing provider and gateway unless the user asks to
change it. If no provider has been chosen, compare the task's capability,
data-handling, deployment, latency, and cost requirements before recommending
one. Use AI Gateway Reference only when Gateway is
already in use or chosen for a stated reason.
- Verify current model IDs against the selected provider's official catalog.
When Vercel AI Gateway is selected, its
/v1/models endpoint is one useful
source. Do not infer recency from response order or choose the numerically
highest ID automatically; select a stable model that supports the required
tools, modalities, context, and structured-output behavior.
- Run typecheck after changes to ensure code is correct
- Be minimal - Only specify options that differ from defaults. When unsure of defaults, check docs or source rather than guessing or over-specifying.
If you cannot find documentation to support your answer, state that explicitly.
Finding Documentation
Search bundled docs and source in node_modules/ai/:
- Docs:
rg "query" node_modules/ai/docs/
- Source:
rg "query" node_modules/ai/src/
Provider packages include docs at node_modules/@ai-sdk/<provider>/docs/.
Earlier versions
- Search:
https://ai-sdk.dev/api/search-docs?q=your_query
- Fetch
.md URLs from results (e.g., https://ai-sdk.dev/docs/agents/building-agents.md)
When Typecheck Fails
Before searching source code, grep Common Errors for the failing property or function name. Many type errors are caused by deprecated APIs documented there.
If not found in common-errors.md:
- Search
node_modules/ai/src/ and node_modules/ai/docs/
- Search ai-sdk.dev (for earlier versions or if not found locally)
Building and Consuming Agents
Creating Agents
Use ToolLoopAgent for iterative tool-using agents when the installed version
documents it as the appropriate abstraction. Simpler generation or a fixed tool
sequence may use a smaller API. Verify the current agent APIs before choosing.
File conventions: See type-safe-agents.md for where to save agents and tools.
Type Safety: When consuming agents with useChat, always use InferAgentUIMessage<typeof agent> for type-safe tool results. See reference.
Consuming Agents (Framework-Specific)
Before implementing agent consumption:
- Check
package.json to detect the project's framework/stack
- Search documentation for the framework's quickstart guide
- Follow the framework-specific patterns for streaming, API routes, and client integration
References
- Common Errors - Renamed parameters reference (parameters → inputSchema, etc.)
- AI Gateway - Gateway setup and usage
- Type-Safe Agents with useChat - End-to-end type safety with InferAgentUIMessage
- DevTools - Set up local debugging and observability (development only)
1---2name: ai-sdk3description: Answer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like generateText, streamText, ToolLoopAgent, embed, or tools, (2) Want to build AI agents, chatbots, RAG systems, or text generation features, (3) Have questions about AI providers (OpenAI, Anthropic, Google, etc.), streaming, tool calling, structured output, or embeddings, (4) Use React hooks like useChat or useCompletion. Triggers on: "AI SDK", "Vercel AI SDK", "generateText", "streamText", "add AI to my app", "build an agent", "tool calling", "structured output", "useChat".4---56## Prerequisites78This information targets AI SDK 7. If the project has the package installed,9compare against `node_modules/ai/package.json` and use documentation matching10that version.1112Before searching remote docs, check whether `node_modules/ai/docs/` exists. If13it does not, use the official versioned documentation at `ai-sdk.dev`. Do not14change project dependencies merely to obtain documentation.1516Install `ai`, provider packages, or client packages only when implementation17requires them and the user's request authorizes adding that functionality. Use18the project's existing package manager and version policy.1920## Critical: Do Not Trust Internal Knowledge2122Everything you know about the AI SDK is outdated or wrong. Your training data contains obsolete APIs, deprecated patterns, and incorrect usage.2324**When working with the AI SDK:**25261. Identify the installed AI SDK version, or the requested target version272. Search `node_modules/ai/docs/` and `node_modules/ai/src/` for current APIs283. If not found locally, search ai-sdk.dev documentation (instructions below)294. Never rely on memory - always verify against source code or docs305. **`useChat` has changed significantly** - check [Common Errors](references/common-errors.md) before writing client code316. Preserve the project's existing provider and gateway unless the user asks to32 change it. If no provider has been chosen, compare the task's capability,33 data-handling, deployment, latency, and cost requirements before recommending34 one. Use [AI Gateway Reference](references/ai-gateway.md) only when Gateway is35 already in use or chosen for a stated reason.367. Verify current model IDs against the selected provider's official catalog.37 When Vercel AI Gateway is selected, its `/v1/models` endpoint is one useful38 source. Do not infer recency from response order or choose the numerically39 highest ID automatically; select a stable model that supports the required40 tools, modalities, context, and structured-output behavior.418. Run typecheck after changes to ensure code is correct429. **Be minimal** - Only specify options that differ from defaults. When unsure of defaults, check docs or source rather than guessing or over-specifying.4344If you cannot find documentation to support your answer, state that explicitly.4546## Finding Documentation4748### ai@6.0.34+4950Search bundled docs and source in `node_modules/ai/`:5152- **Docs**: `rg "query" node_modules/ai/docs/`53- **Source**: `rg "query" node_modules/ai/src/`5455Provider packages include docs at `node_modules/@ai-sdk/<provider>/docs/`.5657### Earlier versions58591. Search: `https://ai-sdk.dev/api/search-docs?q=your_query`602. Fetch `.md` URLs from results (e.g., `https://ai-sdk.dev/docs/agents/building-agents.md`)6162## When Typecheck Fails6364**Before searching source code**, grep [Common Errors](references/common-errors.md) for the failing property or function name. Many type errors are caused by deprecated APIs documented there.6566If not found in common-errors.md:67681. Search `node_modules/ai/src/` and `node_modules/ai/docs/`692. Search ai-sdk.dev (for earlier versions or if not found locally)7071## Building and Consuming Agents7273### Creating Agents7475Use `ToolLoopAgent` for iterative tool-using agents when the installed version76documents it as the appropriate abstraction. Simpler generation or a fixed tool77sequence may use a smaller API. Verify the current agent APIs before choosing.7879**File conventions**: See [type-safe-agents.md](references/type-safe-agents.md) for where to save agents and tools.8081**Type Safety**: When consuming agents with `useChat`, always use `InferAgentUIMessage<typeof agent>` for type-safe tool results. See [reference](references/type-safe-agents.md).8283### Consuming Agents (Framework-Specific)8485Before implementing agent consumption:86871. Check `package.json` to detect the project's framework/stack882. Search documentation for the framework's quickstart guide893. Follow the framework-specific patterns for streaming, API routes, and client integration9091## References9293- [Common Errors](references/common-errors.md) - Renamed parameters reference (parameters → inputSchema, etc.)94- [AI Gateway](references/ai-gateway.md) - Gateway setup and usage95- [Type-Safe Agents with useChat](references/type-safe-agents.md) - End-to-end type safety with InferAgentUIMessage96- [DevTools](references/devtools.md) - Set up local debugging and observability (development only)