| name | ai-sdk |
| description | Expert on Vercel's AI SDK for building AI-powered applications. Use when user wants to integrate LLMs, stream text, generate structured data, use tools, or build agents. Triggers on mentions of ai-sdk, vercel ai, generateText, streamText, useChat, tool calling. |
| allowed-tools | Read, Write, Edit, Glob, Grep, Bash, WebFetch |
AI SDK Skill
Expert at building AI-powered applications with Vercel's AI SDK.
Overview
AI SDK is the TypeScript toolkit for building AI applications:
- Unified API for OpenAI, Anthropic, Google, Cohere, and more
- Core functions: generateText, streamText, generateObject, streamObject
- UI hooks: useChat, useCompletion, useObject
- Tool calling and function execution
- Agent framework with ToolLoopAgent
- Works with React, Next.js, Vue, Svelte, Node.js
Quick Start
npm install ai @ai-sdk/openai
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const { text } = await generateText({
model: openai('gpt-4o'),
prompt: 'What is the weather in San Francisco?',
});
Core Concepts
Core Functions
generateText - Non-interactive text generation
streamText - Real-time streaming for chat
generateObject - Typed structured data with Zod schemas
streamObject - Stream structured objects
UI Hooks
import { useChat } from '@ai-sdk/react';
function Chat() {
const { messages, input, handleInputChange, handleSubmit } = useChat();
}
Tool Calling
const result = await generateText({
model: openai('gpt-4o'),
tools: {
weather: tool({
parameters: z.object({ city: z.string() }),
execute: async ({ city }) => getWeather(city),
}),
},
prompt: 'What is the weather in Tokyo?',
});
Documentation
For detailed information, see the reference documentation:
Common Workflows
Streaming Chat with React
'use client';
import { useChat } from '@ai-sdk/react';
export default function Chat() {
const { messages, input, handleSubmit, handleInputChange } = useChat();
return (
<div>
{messages.map(m => <div key={m.id}>{m.content}</div>)}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
</form>
</div>
);
}
Switch Providers
import { anthropic } from '@ai-sdk/anthropic';
const { text } = await generateText({
model: anthropic('claude-3-5-sonnet-20241022'),
prompt: 'Hello!',
});
Upstream Sources
Sync & Update
When user runs sync: fetch latest from upstream sources, update docs/ files.
When user runs diff: compare current vs upstream, report changes.