Build backend AI with Vercel AI SDK v6 stable. Covers Output API (replaces generateObject/streamObject), speech synthesis, transcription, embeddings, MCP tools with security guidance. Includes v4→v5 migration and 15 error solutions with workarounds. Use when: implementing AI SDK v5/v6, migrating versions, troubleshooting AI_APICallError, Workers startup issues, Output API errors, Gemini caching issues, Anthropic tool errors, MCP tools, or stream resumption failures.
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install ai-sdk-core或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install ai-sdk-core⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/ai-sdk-core/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: ai-sdk-core description: | Build backend AI with Vercel AI SDK v6 stable. Covers Output API (replaces generateObject/streamObject), speech synthesis, transcription, embeddings, MCP tools with security guidance. Includes v4→v5 migration and 15 error solutions with workarounds.
Use when: implementing AI SDK v5/v6, migrating versions, troubleshooting AI_APICallError, Workers startup issues, Output API errors, Gemini caching issues, Anthropic tool errors, MCP tools, or stream resumption failures. user-invocable: true ---
Backend AI with Vercel AI SDK v5 and v6.
Installation:
npm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google zod
---
Status: Stable Latest: [email protected] (Jan 2026)
⚠️ CRITICAL: generateObject() and streamObject() are DEPRECATED and will be removed in a future version. Use the new Output API instead.
Before (v5 - DEPRECATED):
// ❌ DEPRECATED - will be removed
import { generateObject } from 'ai';
const result = await generateObject({
model: openai('gpt-5'),
schema: z.object({ name: z.string(), age: z.number() }),
prompt: 'Generate a person',
});
After (v6 - USE THIS):
// ✅ NEW OUTPUT API
import { generateText, Output } from 'ai';
const result = await generateText({
model: openai('gpt-5'),
output: Output.object({ schema: z.object({ name: z.string(), age: z.number() }) }),
prompt: 'Generate a person',
});
// Access the typed object
console.log(result.object); // { name: "Alice", age: 30 }
import { generateText, Output } from 'ai';
// Object with Zod schema
output: Output.object({ schema: myZodSchema })
// Array of typed objects
output: Output.array({ schema: personSchema })
// Enum/choice from options
output: Output.choice({ choices: ['positive', 'negative', 'neutral'] })
// Plain text (explicit)
output: Output.text()
// Unstructured JSON (no schema validation)
output: Output.json()
import { streamText, Output } from 'ai';
const result = streamText({
model: openai('gpt-5'),
output: Output.object({ schema: personSchema }),
prompt: 'Generate a person',
});
// Stream partial objects
for await (const partialObject of result.objectStream) {
console.log(partialObject); // { name: "Ali..." } -> { name: "Alice", age: ... }
}
// Get final object
const finalObject = await result.object;
1. Agent Abstraction Unified interface for building agents with ToolLoopAgent class:
2. Tool Execution Approval (Human-in-the-Loop)
Use selective approval for better UX. Not every tool call needs approval.
tools: {
payment: tool({
// Dynamic approval based on input
needsApproval: async ({ amount }) => amount > 1000,
inputSchema: z.object({ amount: z.number() }),
execute: async ({ amount }) => { /* process payment */ },
}),
readFile: tool({
needsApproval: false, // Safe operations don't need approval
inputSchema: z.object({ path: z.string() }),
execute: async ({ path }) => fs.readFile(path),
}),
deleteFile: tool({
needsApproval: true, // Destructive operations always need approval
inputSchema: z.object({ path: z.string() }),
execute: async ({ path }) => fs.unlink(path),
}),
}
Best Practices:
Sources:
3. Reranking for RAG
import { rerank } from 'ai';
const result = await rerank({
model: cohere.reranker('rerank-v3.5'),
query: 'user question',
documents: searchResults,
topK: 5,
});
4. MCP Tools (Model Context Protocol)
⚠️ SECURITY WARNING: MCP tools have significant production risks. See security section below.
import { experimental_createMCPClient } from 'ai';
const mcpClient = await experimental_createMCPClient({
transport: { type: 'stdio', command: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem'] },
});
const tools = await mcpClient.tools();
const result = await generateText({
model: openai('gpt-5'),
tools,
prompt: 'List files in the current directory',
});
Known Issue: MCP tools may not execute in streaming mode (Vercel Community Discussion). Use generateText() instead of streamText() for MCP tools.
MCP Security Considerations
⚠️ CRITICAL: Dynamic MCP tools in production have security risks:
Risks:
Solution - Use Static Tool Generation:
// ❌ RISKY: Dynamic tools change without your control
const mcpClient = await experimental_createMCPClient({ /* ... */ });
const tools = await mcpClient.tools(); // Can change anytime!
// ✅ SAFE: Generate static, versioned tool definitions
// Step 1: Install mcp-to-ai-sdk
npm install -g mcp-to-ai-sdk
// Step 2: Generate static tools (one-time, version controlled)
npx mcp-to-ai-sdk generate stdio 'npx -y @modelcontextprotocol/server-filesystem'
// Step 3: Import static tools
import { tools } from './generated-mcp-tools';
const result = await generateText({
model: openai('gpt-5'),
tools, // Static, reviewed, versioned
prompt: 'Use tools',
});
Best Practice: Generate static tools, review them, commit to version control, and only update intentionally.
Source: Vercel Blog: MCP Security
5. Language Model Middleware
import { wrapLanguageModel, extractReasoningMiddleware } from 'ai';
const wrappedModel = wrapLanguageModel({
model: anthropic('claude-sonnet-4-5-20250929'),
middleware: extractReasoningMiddleware({ tagName: 'think' }),
});
// Reasoning extracted automatically from <think>...</think> tags
6. Telemetry (OpenTelemetry)
const result = await generateText({
model: openai('gpt-5'),
prompt: 'Hello',
experimental_telemetry: {
isEnabled: true,
functionId: 'my-chat-function',
metadata: { userId: '123' },
recordInputs: true,
recordOutputs: true,
},
});
Official Docs: https://ai-sdk.dev/docs
---
GPT-5.2 (Dec 2025):
GPT-5.1 (Nov 2025):
GPT-5 (Aug 2025):
o3 Reasoning Models (Dec 2025):
...
安装 Ai Sdk Core 后,可以对 AI 说这些话来触发它
Help me get started with Ai Sdk Core
Explains what Ai Sdk Core does, walks through the setup, and runs a quick demo based on your current project
Use Ai Sdk Core to build backend AI with Vercel AI SDK v6 stable
Invokes Ai Sdk Core with the right parameters and returns the result directly in the conversation
What can I do with Ai Sdk Core in my developer & devops workflow?
Lists the top use cases for Ai Sdk Core, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/ai-sdk-core/ 目录(个人级,所有项目可用),或 .claude/skills/ai-sdk-core/(项目级)。重启 AI 客户端后,用 /ai-sdk-core 主动调用,或让 AI 根据上下文自动发现并使用。
Ai Sdk Core 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Ai Sdk Core 可免费安装使用。请查阅仓库了解许可证信息。
Build backend AI with Vercel AI SDK v6 stable. Covers Output API (replaces generateObject/streamObject), speech synthesis, transcription, embeddings, MCP tools with security guidance. Includes v4→v5 migration and 15 error solutions with workarounds. Use when: implementing AI SDK v5/v6, migrating versions, troubleshooting AI_APICallError, Workers startup issues, Output API errors, Gemini caching issues, Anthropic tool errors, MCP tools, or stream resumption failures.
Automate my developer & devops tasks using Ai Sdk Core
Identifies repetitive steps in your workflow and sets up Ai Sdk Core to handle them automatically
Ai Sdk Core 属于「Developer & DevOps」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。