Vercel AI SDK
January 30, 2026
The Vercel AI SDK (also known as the AI SDK) is a TypeScript library that provides a unified API for working with AI models from multiple providers. Write once, swap providers freely.
Core Proposition
Instead of learning provider-specific APIs:
// Before: Provider-specific
import OpenAI from 'openai';
import Anthropic from '@anthropic-ai/sdk';
// Different APIs, different patterns...
Use one consistent interface:
import { generateText } from "ai";
const { text } = await generateText({
model: "anthropic/claude-sonnet-4.5",
prompt: "What is love?",
});
The SDK handles provider differences behind a consistent abstraction.
Key Features
Provider Agnostic
Swap between providers by changing a string:
- OpenAI (
openai/gpt-4o) - Anthropic (
anthropic/claude-sonnet-4.5) - Google (
google/gemini-2.0-flash) - Mistral, Cohere, and more
Streaming First
Built for real-time AI interactions:
import { streamText } from "ai";
const stream = await streamText({
model: "anthropic/claude-sonnet-4.5",
prompt: "Write a poem about coding",
});
for await (const chunk of stream) {
process.stdout.write(chunk);
}
Tool Calling
Function calling with type safety:
import { generateText, tool } from "ai";
import { z } from "zod";
const result = await generateText({
model: "openai/gpt-4o",
tools: {
weather: tool({
description: "Get weather for a location",
parameters: z.object({
city: z.string(),
}),
execute: async ({ city }) => {
return { temp: 72, condition: "sunny" };
},
}),
},
prompt: "What's the weather in Tokyo?",
});
Structured Output
Parse model responses into typed objects:
import { generateObject } from "ai";
import { z } from "zod";
const { object } = await generateObject({
model: "openai/gpt-4o",
schema: z.object({
name: z.string(),
age: z.number(),
hobbies: z.array(z.string()),
}),
prompt: "Generate a fictional person profile",
});
Agent Support (v5+)
Version 5 introduced experimental agent primitives:
import { experimental_createAgent as createAgent } from "ai";
const agent = createAgent({
model: "anthropic/claude-sonnet-4.5",
tools: { /* ... */ },
system: "You are a helpful assistant",
});
const result = await agent.run("Research the latest AI news");
As noted on Twitter:
ai-sdk-tools/agents orchestrates multiple specialized agents with automatic routing, seamless handoffs, and preserved context.
Multi-Agent Orchestration
Community extensions enable sophisticated patterns:
// Specialized agents for different tasks
const researchAgent = createAgent({ /* research-focused */ });
const analysisAgent = createAgent({ /* analysis-focused */ });
const writingAgent = createAgent({ /* writing-focused */ });
// Orchestrate with handoffs
const result = await orchestrate({
agents: [researchAgent, analysisAgent, writingAgent],
task: "Write a market analysis report",
});
Workflow Patterns
The SDK supports common orchestration patterns:
- Sequential: Chain model calls
- Parallel: Run independent calls simultaneously
- Conditional: Branch based on outputs
- Agentic loops: Iterate until completion
React Hooks
For frontend integration:
import { useChat } from "ai/react";
function ChatUI() {
const { messages, input, handleInputChange, handleSubmit } = useChat();
return (
<div>
{messages.map(m => <div key={m.id}>{m.content}</div>)}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
</form>
</div>
);
}
When to Use It
Good fit:
- TypeScript/JavaScript projects
- Need provider flexibility
- Building Next.js or React apps
- Want streaming out of the box
- Need structured output parsing
Consider alternatives when:
- Python-only codebase
- Need low-level provider control
- Complex multi-agent systems (consider LangGraph)
Installation
npm install ai @ai-sdk/openai @ai-sdk/anthropic
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { anthropic } from "@ai-sdk/anthropic";
Sources
- AI SDK Documentation — Official docs
- Vercel Blog — AI SDK announcements
- GitHub: vercel/ai — Source code
See also: TanStack AI · LangChain · Orchestration