AI SDK
Vercel's unified SDK for building AI apps with OpenAI, Anthropic, Google and more.
Model SDKsNPM
3. Used by agents' projects
Dependency in 280 public GitHub projects set up for AI coding agents that we scanned (4.5%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
ai-sdk.dev/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What AI SDK does
AI SDK puts one TypeScript call, <code>generateText</code>, in front of many model providers, and by default it routes a plain model string like <code>'openai/gpt-6-astra'</code> through Vercel's AI Gateway instead of asking you to wire up each provider.
AI SDK popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How AI SDK is used
- AI SDK is a dependency in 280 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (5.8% of the 4,867 JavaScript/TypeScript ones), #2 of 92 in model sdks.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,554; those are left out of every share on this page.
- The most used alternative in our scan is OpenAI (286 projects).
- Projects that use it most often also use Zod (83.6%), Tailwind Merge (56.1%), Class Variance Authority (52.5%).
- It is more common in projects set up for Kiro (9.3%) than for GitHub Copilot (4.2%).
By coding agent
Often used with
AI SDK in practice
Strengths
Out of the box, the SDK sends requests through the Vercel AI Gateway. A string like <code>'anthropic/claude-opus-5.5'</code> picks the provider and model, with no provider package to install first.
You can skip the gateway. Install <code>@ai-sdk/openai</code>, <code>@ai-sdk/anthropic</code> or <code>@ai-sdk/google</code> and pass <code>anthropic('claude-opus-5-5')</code> to the same <code>generateText</code> call.
<code>generateText</code> takes an <code>output: Output.object({ schema })</code> option with a Zod schema and returns a typed <code>output</code>. The README demonstrates it with a recipe object.
In the README's agent example, each tool invocation reaches the React component with a <code>state</code>. You can show a placeholder at <code>input-available</code> and the result at <code>output-available</code>.
Watch out for
The README sets Node.js 22+ as the requirement for local development.
The README's basic examples pass a bare model string, and its own code comment notes this goes through Vercel AI Gateway. To call a provider directly, you have to install that provider's package.
A 2025 post imports <code>useChat</code> from <code>ai/react</code> and uses <code>handleInputChange</code>. The current README imports it from <code>@ai-sdk/react</code> and calls <code>sendMessage</code>. Check the date on any example before copying it.
Generate a typed object with a Zod schema
import { generateText, Output } from 'ai';
import { z } from 'zod';
const { output } = await generateText({
model: 'openai/gpt-6-astra',
output: Output.object({
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 lasagna recipe.',
});More about AI SDK
Agent Skills for it
- ai-sdk: Answer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like generateText,
Packages around it
- @ai-sdk/openai: OpenAI provider
- @ai-sdk/react: React hooks (useChat)
- @ai-sdk/google: Google provider
- @ai-sdk/anthropic: Anthropic provider
- @ai-sdk/openai-compatible: OpenAI-compatible provider
- @ai-sdk/groq: Groq provider
Alternatives
AI SDK This page
Official TypeScript SDK for accessing OpenAI APIs including GPT and embeddings.
Official TypeScript SDK for calling Claude API and building agent applications.
Official SDK for Google Gemini API to build AI-powered applications.
Official JavaScript client library for Ollama to run and interact with local language models.
Official TypeScript SDK for calling Groq's fast language models API.
JavaScript client library for calling Replicate's AI model API.
Get started
Install it.
npm install aiRules for your agent
## AI SDK
- Install the core package with `npm install ai`, and check that the project runs on Node.js 22+.
- A bare model string such as `'openai/gpt-6-astra'` goes through the Vercel AI Gateway. To call a provider directly, install its package (`@ai-sdk/openai`, `@ai-sdk/anthropic`, `@ai-sdk/google`) and pass e.g. `anthropic('claude-opus-5-5')`.
- For structured data, use `generateText` with `output: Output.object({ schema })` and a Zod schema, then read `output`.
- For chat UIs, install the framework package (e.g. `@ai-sdk/react`), use `useChat`, call `sendMessage({ text })`, and render `message.parts` by `part.type`.
- Render tool parts by `invocation.state`: handle `'input-available'` and `'output-available'`.
- In Next.js routes that stream agent output, return `createAgentUIStreamResponse({ agent, messages })`. The RSC examples also set `export const maxDuration = 30` to allow streaming up to 30 seconds.
- If the repo uses Claude Code or Cursor, add the official skill with `npx skills add vercel/ai`.