skills/ai-sdk-core/SKILL.md
Expert guidance for AI SDK Core: text generation, structured data, tool calling (tool/dynamicTool), MCP integration (createMCPClient, Experimental_StdioMCPTransport), embeddings/reranking, provider setup, middleware, telemetry, and error handling. Use when building with generateText/streamText, generateObject/streamObject, tools (needsApproval, strict, inputExamples, activeTools, toolChoice, experimental_context), embeddings (embed/embedMany/rerank), or MCP tools/resources/prompts/elicitation.
npx skillsauth add bjornmelin/dev-skills ai-sdk-coreInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use AI SDK Core to generate text/structured output, call tools, and connect to MCP servers with consistent APIs across providers.
pnpm add ai @ai-sdk/openai zod@^4.3.5
import { generateText } from 'ai';
const { text } = await generateText({
model: 'openai/gpt-4o',
prompt: 'Explain quantum computing in one paragraph.',
});
| Need | Function | Streaming |
|------|----------|-----------|
| Text response | generateText | No |
| Streaming text | streamText | Yes |
| Structured JSON | generateObject | No |
| Streaming JSON | streamObject | Yes |
| Embeddings | embed / embedMany | No |
| Rerank | rerank | No |
import { generateText } from 'ai';
const { text, usage } = await generateText({
model: 'anthropic/claude-sonnet-4.5',
system: 'You are a helpful assistant.',
prompt: 'What is the capital of France?',
});
import { streamText } from 'ai';
const result = streamText({
model: 'openai/gpt-4o',
prompt: 'Write a short story.',
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
import { generateObject } from 'ai';
import { z } from 'zod';
const { object } = await generateObject({
model: 'openai/gpt-4o',
schema: z.object({
recipe: z.object({
name: z.string(),
ingredients: z.array(z.object({ name: z.string(), amount: z.string() })),
steps: z.array(z.string()),
}),
}),
prompt: 'Generate a recipe for chocolate chip cookies.',
});
import { generateText, tool } from 'ai';
import { z } from 'zod';
const { text, toolCalls } = await generateText({
model: 'openai/gpt-4o',
tools: {
weather: tool({
description: 'Get weather for a location',
inputSchema: z.object({ location: z.string() }),
execute: async ({ location }) => ({ temperature: 72, condition: 'sunny' }),
}),
},
prompt: 'What is the weather in San Francisco?',
});
import { dynamicTool } from 'ai';
import { z } from 'zod';
const customTool = dynamicTool({
description: 'Execute a custom function',
inputSchema: z.object({}),
execute: async input => ({ ok: true, input }),
});
import { generateText, stepCountIs } from 'ai';
const { steps } = await generateText({
model: 'openai/gpt-4o',
tools: { search, analyze, summarize },
stopWhen: stepCountIs(5),
prompt: 'Research and summarize AI developments.',
});
tool() for typed inputs and dynamicTool() for unknown schemas.needsApproval for sensitive actions (tool-approval-request/response flow).stopWhen with stepCountIs/hasToolCall for multi-step loops.prepareStep for per-step controls (model swap, toolChoice, activeTools, prompt compression).experimental_context when tools need app-specific context.inputExamples and strict to improve tool call reliability.createMCPClient() to load MCP tools, resources, and prompts.Experimental_StdioMCPTransport only for local Node.js servers.onFinish).See references/mcp-integration.md for transports, schema definition, outputSchema typing, and elicitation.
| Reference | When to Use |
|-----------|-------------|
| references/text-generation.md | generateText/streamText callbacks, streaming, response handling |
| references/structured-data.md | generateObject/streamObject, Output API, Zod patterns |
| references/tool-calling.md | tool/dynamicTool, approval flow, repair, activeTools, hooks |
| references/dynamic-tools.md | dynamicTool patterns, MCP + dynamic tools, large tool sets |
| references/embeddings-rag.md | embed/embedMany, rerank, chunking |
| references/providers.md | OpenAI/Anthropic/Google setup, registry, AI Gateway |
| references/middleware.md | wrapLanguageModel, built-in/custom middleware |
| references/mcp-integration.md | MCP client, transports, tools/resources/prompts/elicitation |
| references/production.md | Telemetry, error handling, testing, cost control |
| references/migration.md | v6 upgrade notes |
import { generateText, AI_APICallError } from 'ai';
try {
await generateText({ model: 'openai/gpt-4o', prompt: 'Hello' });
} catch (error) {
if (error instanceof AI_APICallError) {
console.error('API Error:', error.message);
}
}
import { openai } from '@ai-sdk/openai';
const { text } = await generateText({
model: openai('gpt-4o'),
prompt: 'Hello!',
});
package.json to avoid breaking changes.Before AI SDK migrations or reviews, run the deterministic scanner from the target repository:
python3 skills/ai-sdk-core/scripts/ai_stack_scan.py --root <repo> --family ai-sdk-core --pretty
The scanner emits ai_stack_scan.v1 JSON, performs no network calls, skips
symlinks, and checks package manifests plus source signals such as legacy
maxSteps, removed stream response helpers, missing inputSchema, and MCP
clients without visible cleanup. Treat every signal as a review prompt, then
verify with the current AI SDK docs or package source before editing. Keep full
scanner JSON local; share only specific redacted signals externally.
development
Repo/monorepo modernization: dependency upgrades, security fixes, deprecation cleanup, framework migrations, dependency-native refactors, and verified hard-cut simplification.
development
Use this skill for Browser Web Animations API: Element.animate(), Animation, KeyframeEffect, playback control, generated keyframes, cancel/finish, commitStyles, and cleanup. Trigger on Element.animate, WAAPI, Web Animations API, KeyframeEffect, Animation object, commitStyles. Do not use for near-miss tasks outside these boundaries; route to adjacent motion or platform skills when they own the implementation.
tools
Use this skill for Three.js, React Three Fiber, Drei, Canvas/createRoot lifecycle, loaders, GLTF, useFrame, disposal, SSR/client boundaries, DPR, and browser proof. Trigger on Three.js, THREE, @react-three/fiber, @react-three/drei, R3F Canvas, useFrame, GLTF, WebGLRenderer. Do not use for near-miss tasks outside these boundaries; route to adjacent motion or platform skills when they own the implementation.
development
Use this skill for Tailwind CSS v4 transition, animation, duration, easing, motion-safe/motion-reduce, @theme motion tokens, and static class safety. Trigger on Tailwind animation, transition-all, motion-safe, motion-reduce, @theme, animate-, duration-. Do not use for near-miss tasks outside these boundaries; route to adjacent motion or platform skills when they own the implementation.