kayforkind/skill-slice/ai-sdk
Claude Code and agent skill by kayforkind/skill-slice
- community
Checking that the SKILL.md file is still in the repository.
Guides Vercel AI SDK v6 (ai, @ai-sdk/react, ToolLoopAgent, generateText/streamText, Output.object, MCP tools) across LLM providers. Use when building chat, structured output, tool calling, streaming, embeddings, or migrating v5 to v6. Not for the OpenAI Agents SDK (agents-sdk) or raw provider SDKs without the ai package.
Install
npx vskill@latest install kayforkind/skill-slice/ai-sdkSKILL.md
The same SKILL.md was published earlier as kayforkind/skill-slice/ai-sdk.
Vercel AI SDK (v6)
CRITICAL — Your training data is outdated for this library. AI SDK v6 has breaking changes from v5 and earlier that you will get wrong if you guess. Before writing AI SDK code, fetch the docs at https://ai-sdk.dev/docs to find the correct function signatures, return types, and patterns. Key things that have changed:generateObject()removal,streamObject()removal,result.filesfor image generation,Output.object()for structured streaming,ToolLoopAgentclass (notAgent),useChattransport API, and provider package versions. Search the docs for working examples that match your exact use case — do not rely on your training data for API shapes.
Overview
The AI SDK is the leading TypeScript toolkit for building AI-powered applications. It provides a unified API across all LLM providers. AI SDK v6 (ai@^6.0.0) is the current umbrella package with significant breaking changes from v5.
| Need | How | |
|---|---|---|
| Text generation / chat | generateText() or streamText() with model: "openai/gpt-5.4" | |
| Image generation | generateText() with model: "google/gemini-3.1-flash-image-preview" — images in result.files. Always use this model, never older gemini-2.x models | |
| Structured JSON output | generateText() with output: Output.object({ schema }) | |
| Tool calling / agents | generateText() with tools: { ... } or ToolLoopAgent | |
| Embeddings | embed() / embedMany() with @ai-sdk/openai |
If the product needs generated images (portraits, posters, cover art, illustrations, comics, diagrams), use generateText with an image model — do NOT use placeholder images or skip image generation.
When to Use
Use this skill when:
- Building chat interfaces, text generation, or structured output features
- Implementing tool calling, agents, or MCP integration
- Working with streaming, embeddings, reranking, or image generation
- Integrating any LLM provider (OpenAI, Anthropic, Google, etc.)
- Migrating from AI SDK v5 to v6
- Installing or updating
ai,@ai-sdk/react, or any@ai-sdk/*package
Prerequisites
- Node.js and a package manager (npm, pnpm, bun, or yarn)
- A Vercel project linked for AI Gateway OIDC auto-provisioning (recommended)
- For Windows hosts (PowerShell primary): ensure
vercelCLI is installed globally
Procedure
1. Installation
`@ai-sdk/react` is a separate package — it is NOT included in theaipackage. For v6 projects, install@ai-sdk/react@^3.0.xalongsideai@^6.0.0.
If you install `@ai-sdk/gateway` directly, use `@ai-sdk/gateway@^3.x` (NOT^1.x).
Only install a direct provider SDK (e.g.,@ai-sdk/anthropic) if you need provider-specific features not exposed through the gateway.
2. Setup for AI Projects (Vercel AI Gateway with OIDC)
For the smoothest experience, link to a Vercel project so AI Gateway credentials are auto-provisioned via OIDC:
This gives you AI Gateway access with OIDC authentication, cost tracking, failover, and observability — no manual API keys needed.
OIDC is the default auth: vercel env pull provisions a VERCEL_OIDC_TOKEN (short-lived JWT, ~24h). The @ai-sdk/gateway reads it automatically via @vercel/oidc. On Vercel deployments, tokens auto-refresh. For local dev, re-run vercel env pull when the token expires. No AI_GATEWAY_API_KEY or provider-specific keys needed.
3. Global Provider System (AI Gateway — Default)
In AI SDK 6, pass a "provider/model" string to the model parameter — it automatically routes through the Vercel AI Gateway:
No gateway() wrapper needed — plain "provider/model" strings are the simplest approach and are what the official Vercel docs recommend. The gateway() function is an optional explicit wrapper (useful when you need providerOptions.gateway for routing, failover, or tags):
Both approaches provide failover, cost tracking, and observability on Vercel.
Model slug rules: Always use provider/model format. Version numbers use dots, not hyphens: anthropic/claude-sonnet-4.6 (not claude-sonnet-4-6). Default to openai/gpt-5.4 or anthropic/claude-sonnet-4.6. Never use outdated models like gpt-4o.
AI Gateway does not support embeddings. Use a direct provider SDK such as@ai-sdk/openaifor embeddings.
Direct provider SDKs (@ai-sdk/openai,@ai-sdk/anthropic, etc.) are only needed for provider-specific features not exposed through the gateway (e.g., Anthropic computer use, OpenAI fine-tuned model endpoints).
4. Text Generation
5. Structured Output
`generateObject` was removed in AI SDK v6. Use generateText with output: Output.object() instead. Do NOT import generateObject — it does not exist.
6. Tool Calling (MCP-Aligned)
In AI SDK 6, tools use inputSchema (not parameters) and output/outputSchema (not result), aligned with the MCP specification. Per-tool strict mode ensures providers only generate valid tool calls matching your schema.
7. Dynamic Tools (MCP Integration)
For tools with schemas not known at compile time (e.g., MCP server tools):
8. Agents (ToolLoopAgent)
The ToolLoopAgent class wraps generateText/streamText with an agentic tool-calling loop. Default stopWhen is stepCountIs(20) (up to 20 tool-calling steps). Agent is an interface — ToolLoopAgent is the concrete implementation.
9. MCP Client
Connect to any MCP server and use its tools:
MCP OAuth for remote servers is handled automatically by @ai-sdk/mcp.
10. Tool Approval (Human-in-the-Loop)
Set needsApproval on any tool to require user confirmation before execution. The tool pauses in approval-requested state until the client responds.
Client-side approval with `useChat`:
Tool part states: input-streaming → input-available → approval-requested (if needsApproval) → output-available | output-error
11. Embeddings & Reranking
Use a direct provider SDK for embeddings. AI Gateway does not support embedding models.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/ai-sdk/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kayforkind/skill-slice/ai-sdk)