Production-ready backend AI with Vercel AI SDK v5.
/plugin marketplace add secondsky/claude-skills/plugin install ai-sdk-core@claude-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/core-functions.mdreferences/error-catalog.mdreferences/links-to-official-docs.mdreferences/production-guide.mdreferences/production-patterns.mdreferences/provider-setup.mdreferences/providers-quickstart.mdreferences/tools-and-agents.mdreferences/top-errors.mdreferences/v4-to-v5-migration.mdreferences/v5-breaking-changes.mdscripts/check-versions.shtemplates/agent-with-tools.tstemplates/anthropic-setup.tstemplates/cloudflare-worker-integration.tstemplates/generate-object-zod.tstemplates/generate-text-basic.tstemplates/google-setup.tstemplates/multi-step-execution.tstemplates/nextjs-server-action.tsProduction-ready backend AI with Vercel AI SDK v5.
Last Updated: 2025-11-21
bun add ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google workers-ai-provider zod # preferred
# or: npm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google workers-ai-provider zod
# .env
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_GENERATIVE_AI_API_KEY=...
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const result = await generateText({
model: openai('gpt-4-turbo'),
prompt: 'What is TypeScript?',
});
console.log(result.text);
import { streamText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
const stream = streamText({
model: anthropic('claude-sonnet-4-5-20250929'),
messages: [
{ role: 'user', content: 'Tell me a story' },
],
});
for await (const chunk of stream.textStream) {
process.stdout.write(chunk);
}
import { generateObject } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
const result = await generateObject({
model: openai('gpt-4'),
schema: z.object({
name: z.string(),
age: z.number(),
skills: z.array(z.string()),
}),
prompt: 'Generate a person profile for a software engineer',
});
console.log(result.object);
// { name: "Alice", age: 28, skills: ["TypeScript", "React"] }
Load references/core-functions.md for complete API reference of all 4 core functions.
AI SDK v5 provides 4 core functions:
| Function | Output | Streaming | Use Case |
|---|---|---|---|
generateText() | Text | No | Batch processing, simple completions |
streamText() | Text | Yes | Chat UIs, long responses |
generateObject() | Structured | No | Data extraction, JSON generation |
streamObject() | Structured | Yes | Real-time forms, progressive UIs |
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const result = await generateText({
model: openai('gpt-4-turbo'),
prompt: 'Explain quantum computing',
});
console.log(result.text);
→ Load references/core-functions.md for: Complete signatures, tool usage patterns, error handling, streaming examples, comparison table
Load references/provider-setup.md for complete setup instructions for all providers.
AI SDK v5 supports 4 major providers:
| Provider | Environment Variable | Latest Models |
|---|---|---|
| OpenAI | OPENAI_API_KEY | GPT-5, GPT-4 Turbo |
| Anthropic | ANTHROPIC_API_KEY | Claude Sonnet 4.5, Opus 4 |
GOOGLE_GENERATIVE_AI_API_KEY | Gemini 2.5 Pro/Flash | |
| Cloudflare | Workers AI binding | Llama 3.1, Qwen 2.5 |
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
// API key from environment
const result = await generateText({
model: openai('gpt-4-turbo'),
prompt: 'Hello',
});
→ Load references/provider-setup.md for: Complete API configuration, rate limiting, error handling, Cloudflare Workers optimization, model selection guides
Load references/tools-and-agents.md for complete tool and agent documentation.
Tools allow models to call external functions. Agents manage multi-step workflows.
v5 Tool Changes:
parameters → inputSchema (Zod schema)args → input, result → outputmaxSteps → stopWhen(stepCountIs(n))import { generateText, tool } from 'ai';
import { z } from 'zod';
const result = await generateText({
model: openai('gpt-4'),
tools: {
weather: tool({
description: 'Get weather for a location',
inputSchema: z.object({ location: z.string() }),
execute: async ({ location }) => {
return { temperature: 72, condition: 'sunny' };
},
}),
},
prompt: 'What is the weather in Tokyo?',
});
→ Load references/tools-and-agents.md for: Agent class usage, multi-step execution, dynamic tools, stop conditions
Load references/v4-to-v5-migration.md for complete migration guide.
AI SDK v5 has 9 major breaking changes:
maxTokens → maxOutputTokensparameters → inputSchema (Zod)maxSteps → stopWhen(stepCountIs(n))CoreMessage → ModelMessageai/rsc → @ai-sdk/rsc)bunx ai migrate # Auto-migrates most changes
→ Load references/v4-to-v5-migration.md for: Complete breaking changes list, migration examples, checklist, official migration guide link
Cause: API request failed (network, auth, rate limit).
Solution:
import { AI_APICallError } from 'ai';
try {
const result = await generateText({
model: openai('gpt-4'),
prompt: 'Hello',
});
} catch (error) {
if (error instanceof AI_APICallError) {
console.error('API call failed:', error.message);
console.error('Status code:', error.statusCode);
console.error('Response:', error.responseBody);
// Check common causes
if (error.statusCode === 401) {
// Invalid API key
} else if (error.statusCode === 429) {
// Rate limit - implement backoff
} else if (error.statusCode >= 500) {
// Provider issue - retry
}
}
}
Prevention:
Cause: Model didn't generate valid object matching schema.
Solution:
import { AI_NoObjectGeneratedError } from 'ai';
try {
const result = await generateObject({
model: openai('gpt-4'),
schema: z.object({ /* complex schema */ }),
prompt: 'Generate data',
});
} catch (error) {
if (error instanceof AI_NoObjectGeneratedError) {
console.error('No valid object generated');
// Solutions:
// 1. Simplify schema
// 2. Add more context to prompt
// 3. Provide examples in prompt
// 4. Try different model (gpt-4 better than gpt-3.5 for complex objects)
}
}
Prevention:
Cause: AI SDK v5 + Zod initialization overhead in Cloudflare Workers exceeds startup limits.
Solution:
// BAD: Top-level imports cause startup overhead
import { createWorkersAI } from 'workers-ai-provider';
import { complexSchema } from './schemas';
const workersai = createWorkersAI({ binding: env.AI });
// GOOD: Lazy initialization inside handler
export default {
async fetch(request, env) {
const { createWorkersAI } = await import('workers-ai-provider');
const workersai = createWorkersAI({ binding: env.AI });
// Use workersai here
}
}
Prevention:
GitHub Issue: Search for "Workers startup limit" in Vercel AI SDK issues
→ Load references/error-catalog.md for errors #4-#12 with complete solutions.
Remaining 9 errors: 4. streamText Fails Silently (RESOLVED in v4.1.22) 5. AI_LoadAPIKeyError 6. AI_InvalidArgumentError 7. AI_NoContentGeneratedError 8. AI_TypeValidationError 9. AI_RetryError 10. Rate Limiting Errors 11. TypeScript Performance with Zod 12. Invalid JSON Response (Provider-Specific)
For complete error catalog: See complete error reference at https://ai-sdk.dev/docs/reference/ai-sdk-errors
Load references/production-guide.md for complete production deployment guide.
// Use streaming for user-facing responses
const stream = streamText({
model: openai('gpt-4'),
prompt: 'Long essay',
maxOutputTokens: 500,
maxRetries: 3,
});
return stream.toDataStreamResponse();
→ Load references/production-guide.md for: Platform-specific patterns, deployment checklists, optimization strategies
Load references/core-functions.md when:
Load references/provider-setup.md when:
Load references/tools-and-agents.md when:
Load references/v4-to-v5-migration.md when:
Load references/error-catalog.md when:
Load references/production-guide.md when:
{
"dependencies": {
"ai": "^5.0.116",
"@ai-sdk/openai": "^2.0.88",
"@ai-sdk/anthropic": "^2.0.56",
"@ai-sdk/google": "^2.0.51",
"workers-ai-provider": "^2.0.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^24.10.1",
"typescript": "^5.9.3"
}
}
Version Notes:
.default() behavior, ZodError.errors removedzod-to-json-schema when using Zod 4Check Latest Versions:
npm view ai version
npm view @ai-sdk/openai version
npm view @ai-sdk/anthropic version
npm view @ai-sdk/google version
npm view workers-ai-provider version
npm view zod version # Check for Zod 4.x updates
This skill includes:
templates/references/scripts/All files are optimized for copy-paste into your project.
Last Updated: 2025-12-22 Skill Version: 1.1.0 AI SDK Version: 5.0.116+
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.