What Is the Vercel AI SDK? LLM Toolkit

Photo: Daniil Komov / Pexels
The Vercel AI SDK (published on npm as ai, formerly @vercel/ai) is an open-source TypeScript toolkit for building AI-powered products. It gives developers one unified API across large language model providers — OpenAI, Anthropic, Google, Mistral, xAI, and dozens more — plus dedicated React, Next.js, Svelte, and Vue helpers for streaming chat interfaces and tool-using agents. As of mid-2026 it's pulling roughly 19.5 million weekly downloads on npm, according to the official AI SDK site, which is not a small niche library at that point — it's closer to a default choice for TypeScript teams shipping anything AI-related.
It first shipped in 2023, hit a stable v4 in 2024, and has gone through two major rewrites since: AI SDK 5 in July 2025 and AI SDK 6 in December 2025. Each version pushed the SDK further from "convenience wrapper" toward "the framework most TypeScript teams reach for before touching a raw provider SDK."
What problem does it actually solve?
Think about what happens when you wire an AI feature directly against a single provider's SDK — say, the Anthropic SDK or the OpenAI SDK. It works, right up until it doesn't scale with your product. Three specific pains show up almost every time.
Vendor lock-in. Switching your app's main model from, say, GPT-5 to Claude means rewriting your request shape, your streaming handler, and your tool-call format, because every provider's SDK has its own conventions. That's not a five-minute change; it's a multi-day migration touching every call site.
Streaming UI is genuinely hard to build well. Wiring server-sent events into a React component, parsing partial JSON as it arrives, debouncing UI updates, handling client-side cancellation when a user closes a tab mid-generation — most teams write this exact plumbing once, ship it with bugs, and then rewrite it a year later once they understand the edge cases.
No type safety across providers. Each vendor SDK defines its own message shape and its own tool-definition format. If you build an internal abstraction to normalize them, you're now maintaining a mini-SDK of your own, indefinitely, as a side project nobody signed up to own.
The Vercel AI SDK is a deliberately thin, strongly typed wrapper that solves all three at once: one function signature works across providers, streaming is handled for you end to end, and TypeScript's type system catches mismatches at compile time instead of in production logs.
The single most surprising fact here: the SDK claims roughly 90% of the flexibility of a raw provider SDK with about 10% of the boilerplate — and its own maintainers describe it, in the AI SDK 5 release post, as processing type-safe chat state across four separate frontend frameworks (React, Vue, Svelte, Angular) from one shared core, something no competing toolkit had shipped before mid-2025.
The core APIs, and what each one is actually for
The SDK's surface area is small on purpose. There are four function families that cover almost every use case, plus a set of framework-specific UI hooks.
generateText — single-shot generation, one provider away from any other
This is the simplest entry point: send a prompt, get text back, with the exact same call shape regardless of which model answers it.
import { generateText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
const { text } = await generateText({
model: anthropic('claude-sonnet-4'),
prompt: 'Explain quantum entanglement in one sentence.',
});
Swap anthropic('claude-sonnet-4') for openai('gpt-5') and the rest of the code doesn't change. That's the whole point — the provider becomes a configuration detail instead of an architectural decision baked into every call site in your app.
streamText — the same idea, but token by token
streamText returns an async iterable of text deltas as the model generates them, plus a helper that pipes the stream directly into a Next.js Response object using server-sent events. As of AI SDK 5, this streaming protocol runs natively on SSE rather than a custom Vercel-specific wire format, which the team says makes debugging with browser devtools and standard HTTP tooling straightforward instead of requiring bespoke inspection tools, per the AI SDK 5 announcement.
generateObject / streamObject — structured outputs with a schema, enforced
This is arguably the most practically useful pair of functions in the library. You hand it a Zod schema, and it enforces that shape on the model's output, retries automatically on parse failures, and returns a fully typed object — no more regex-scraping JSON out of a text response.
const { object } = await generateObject({
model: openai('gpt-5'),
schema: z.object({ name: z.string(), age: z.number() }),
prompt: 'Extract: "Alice is 30 years old."',
});
// object.age is typed as number, not `any`
If you've ever tried to parse structured data out of a raw LLM response with string matching, you know how brittle that gets the moment the model decides to add a stray sentence before the JSON. generateObject removes that failure mode almost entirely.
tool() and the agentic loop
Tools are how a model reaches outside its own context window to do something — call an API, query a database, run a calculation. You define a tool once, with a schema for its inputs and an execute function, and the SDK manages the back-and-forth loop between the model and your code.
AI SDK 5 introduced stopWhen and prepareStep as the primary controls over that loop: stopWhen defines the condition under which a multi-step tool-calling sequence halts (a step count, a specific tool being called, a custom predicate), and prepareStep lets you adjust parameters mid-loop — swapping models between steps, for instance, or injecting different instructions depending on how far the agent has gotten. Both are documented in the AI SDK 5 release notes.
AI SDK 6, released December 22, 2025, went a step further and formalized this into a reusable Agent abstraction — specifically a ToolLoopAgent class. Instead of configuring a model, its instructions, and its tools inline every time you call generateText, you define the agent once and reuse it across your entire application. The AI SDK 6 blog post frames this as a shift "from inline configuration to reusable, production-ready agent patterns" — which matches a broader trend across the industry where agent frameworks are converging on the idea that an agent should be a first-class, named, testable object rather than a function call buried in a route handler.
useChat / useCompletion — the UI half of the equation
These are drop-in React (and Svelte, Vue, Angular) hooks that manage the entire lifecycle of a chat interface: message history, streaming state, input handling, regenerate, stop, and error recovery. AI SDK 5 rebuilt this layer around two distinct message types — UIMessage, which represents what your application actually stores and renders, and ModelMessage, which is the format optimized for sending to the LLM. Separating those two was a deliberate fix for a real pain point: earlier versions conflated "what the UI needs to render" with "what the model needs to see," which made persisting chat history to a database awkward. The v5 docs describe UIMessage explicitly as the source of truth for application state.
A complete tool-using agent in under 20 lines
Here's what a minimal but functional tool-calling agent looks like end to end:
import { generateText, tool, stepCountIs } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { z } from 'zod';
const { text } = await generateText({
model: anthropic('claude-sonnet-4'),
prompt: 'What is the weather in Istanbul?',
tools: {
weather: tool({
description: 'Get current weather for a city',
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => ({ tempC: 18, condition: 'cloudy' }),
}),
},
stopWhen: stepCountIs(3),
});
That's a complete tool-using agent. The SDK calls the model, sees that it wants to call weather, runs your execute function, feeds the result back into the conversation, and loops — stopping after three steps or once the model produces a final answer, whichever comes first. Note the inputSchema naming: AI SDK 5 renamed the older parameters/result tool fields to inputSchema/outputSchema, one of the more disruptive breaking changes in that release, per the same v5 release notes.
How it compares to other toolkits
Vercel AI SDK vs the field.
| Toolkit | Language | Architectural style | Best fit |
|---|---|---|---|
| Vercel AI SDK | TypeScript | Thin, strongly typed library | Web apps, Next.js, React/Vue/Svelte chat UIs |
| LangChain / LangChain.js | Python + TS | Heavier abstractions, chains, agents | Complex orchestration, deep integration ecosystem |
| LlamaIndex | Python + TS | Retrieval-first | Document Q&A, indexing, RAG pipelines |
| LiteLLM | Python | HTTP proxy / SDK | Cost routing, multi-provider fallback at the infra layer |
| Anthropic SDK | Multi-language | Low-level provider SDK | Maximum control, single-provider apps |
| OpenAI SDK | Multi-language | Low-level provider SDK | OpenAI-only apps |
vs LangChain. LangChain (and its JS port, LangChain.js) takes the opposite bet: more abstraction, more built-in chains, a much larger integration catalog for things like vector databases and document loaders. That buys you a lot out of the box for complex retrieval and multi-agent orchestration, but it comes with a steeper learning curve and a bundle that's noticeably heavier to ship at the edge. In practice, a fairly common production pattern is to run the Vercel AI SDK on the frontend for streaming chat UI while LangChain or LangGraph handles backend orchestration — they're not always an either/or choice.
vs LiteLLM. LiteLLM is Python-centric and commonly deployed as a standalone proxy service sitting in front of your model calls, which makes it a strong pick when the goal is centralized cost control, rate limiting, and automatic failover across providers at the infrastructure layer — independent of whatever language your application code is written in. The Vercel AI SDK, by contrast, is a library that lives inside your TypeScript application rather than a separate service you deploy and operate.
vs raw provider SDKs. The official Anthropic and OpenAI SDKs expose every parameter each provider offers, which matters if you need something genuinely provider-specific — prompt caching controls, provider-side memory, a model-specific sampling parameter. But you're on your own for streaming plumbing, retry logic, and any cross-provider abstraction. The Vercel AI SDK trades a slice of that raw control for a large reduction in code you have to write and maintain yourself.
Does the Vercel AI SDK support Claude, Gemini, and open-source models?
Yes. The AI SDK's provider catalog lists official packages for Anthropic, OpenAI, Google, Mistral, xAI (Grok), Meta, Perplexity, DeepSeek, Moonshot, and more, spanning over 100 models across 19-plus providers as of mid-2026. Any OpenAI-compatible HTTP endpoint also works out of the box, which covers most self-hosted open-source models served through tools like vLLM or Ollama without needing a dedicated provider package.
What changed from v4 to v5 to v6
The version history matters here because the SDK has moved fast enough that a six-month-old blog post can already describe an outdated API surface — worth flagging explicitly, since that's a common trap with anything documenting a tool this actively developed.
AI SDK 4 (2024) was the stabilization release: the unified generateText/streamText/generateObject API surface settled into the shape most developers still recognize today, and the React/Svelte/Vue hooks matured into production-ready primitives.
AI SDK 5 (July 31, 2025) was a substantial architectural rewrite. The headline changes, per Vercel's own release post:
- Split
UIMessage(what the app renders and persists) fromModelMessage(what gets sent to the LLM) - Moved streaming onto native Server-Sent Events instead of a custom protocol
- Renamed tool fields from
parameters/resulttoinputSchema/outputSchema - Added
stopWhenandprepareStepfor controlling multi-step agentic loops - Introduced "data parts" for streaming arbitrary typed data alongside plain text
- Added a unified speech API covering text-to-speech and transcription across OpenAI, ElevenLabs, and Deepgram
- Shipped the first fully typed chat integration spanning React, Vue, Svelte, and Angular from one shared core
AI SDK 6 (December 22, 2025) built directly on top of v5 rather than replacing it, per the AI SDK 6 announcement:
- Introduced the
Agentabstraction, specifically a production-readyToolLoopAgentclass you configure once and reuse - Added human-in-the-loop tool approval via a
needsApprovalflag — useful for anything an agent shouldn't be allowed to do unsupervised, like sending an email or making a purchase - Stabilized Model Context Protocol (MCP) support, including OAuth authentication, resources, prompts, and elicitation
- Added native document reranking and extended image generation to cover inpainting and style transfer
- Brought in provider-specific tools: Anthropic's memory and code execution, OpenAI's shell and file operations, Google's Maps and RAG tools, and xAI's web search and code execution
- Runs on the v3 Language Model Specification while remaining backward compatible with v5, with Vercel describing the migration as requiring "minimal code changes"
For a team evaluating whether to adopt the SDK today, the practical takeaway is that v6 is the current baseline, v5 code migrates with small changes, and anything written against v4-era docs (the parameters/result tool shape, the old streaming protocol) needs updating before it'll run against a current install.
Who is actually using it
Vercel names its own flagship products as reference implementations: Cursor, the AI code editor, uses the AI SDK for its multi-provider model picker, and Vercel's own v0 UI generator is built on it as well. Vercel's AWS case study also names OpenAI, PayPal, Ramp, and Supreme among the customers it helps build for what Vercel calls the "AI-native web," alongside noting integration with Amazon Bedrock for teams that want to route AI SDK calls through Bedrock's model catalog and built-in agentic systems. Beyond named companies, the SDK underpins a large share of the smaller AI-wrapper products that have shipped in the last two to three years — ChatGPT-style clones, internal copilots, and search-assistant products where the team needed a streaming chat UI and multi-provider flexibility without building either from scratch.
The AI Gateway — the optional paid layer
The SDK itself is free and open source under the Apache 2.0 license; you pay the underlying model providers directly for tokens, same as if you called their APIs yourself. Vercel also sells an optional managed proxy called the AI Gateway, and it's worth understanding what it actually adds, because "unified API" and "unified billing" are two different value propositions that get conflated.
Per Vercel's AI Gateway pricing docs, every Vercel team account gets $5 of AI Gateway credit per month once it makes its first request, refreshing on a rolling 30-day basis — enough to experiment without a credit card on file. Beyond that, usage is pay-as-you-go at the underlying provider's list price with no markup from Vercel; you're charged exactly what OpenAI or Anthropic would charge directly. Included at no extra cost: a single endpoint for hundreds of models, spend observability, automatic retries, load balancing, managed provider fallback, and bring-your-own-key support if you'd rather use your own provider accounts. Two optional add-ons carry a small per-request fee: team-wide zero-data-retention agreements and provider allowlisting, each priced at $0.10 per 1,000 successful requests.
The Gateway is entirely optional. Nothing about the core generateText/streamText/generateObject functions requires it — you can point the anthropic() or openai() provider helpers directly at your own API keys and never touch the Gateway at all.
When to reach for it, and when not to
Reach for the Vercel AI SDK when:
- You're building a TypeScript web app, especially on Next.js, where streaming responses need to hit React components with minimal glue code
- You want the ability to switch or A/B test model providers without rewriting request and response handling at every call site
- You need production-grade streaming chat UI with regenerate, stop, and error recovery, and you don't want to hand-roll that state machine
- You want structured outputs enforced by a schema instead of parsed out of free text with regex
- You're building tool-using agents and want the step-loop, retries, and typing handled for you
Look elsewhere when:
- Your stack is Python — reach for LiteLLM, LangChain, or a provider SDK directly instead; the Vercel AI SDK has no Python port
- You need every raw parameter a specific provider exposes and don't want an abstraction layer sitting between you and the API
- You're building a document-heavy RAG pipeline with complex chunking, reranking, and multi-index retrieval — LlamaIndex and LangChain's retrieval tooling are more purpose-built for that, even though AI SDK 6 now ships some native reranking support
- Your team is already deep in LangGraph or another orchestration framework on the backend and only needs a thin frontend streaming layer — in that case the AI SDK's UI hooks alone, without its backend agent abstraction, may be all you actually need
What people get wrong about it
The most common misconception is that the Vercel AI SDK is a Next.js-only tool, presumably because Vercel makes Next.js and the two are marketed together constantly. That's not accurate. The core functions run in any TypeScript runtime — Node, Bun, Deno, and edge runtimes like Cloudflare Workers all work — and the framework-specific pieces are the UI hooks, not the model-calling functions themselves. Next.js is simply the most common pairing because Vercel's own hosting and docs lean into it, not because the library requires it architecturally.
A second common mix-up is treating "Vercel AI SDK" and "Vercel AI Gateway" as the same product. They're not. The SDK is a client-side library you install with npm; the Gateway is a separate, optional hosted proxy service you pay for by usage. You can use the SDK with zero Gateway involvement by supplying your own provider API keys directly, and plenty of production apps do exactly that.
A third mistake worth flagging given how fast the SDK ships: pasting old parameters/result tool syntax from a pre-v5 tutorial into a current project and being confused when it doesn't type-check. That field naming changed to inputSchema/outputSchema in AI SDK 5 (July 2025), and any code sample dated before that release needs a manual update, not a copy-paste.
The takeaway
The Vercel AI SDK's real contribution isn't any single function — it's collapsing the three most repetitive, error-prone pieces of building an LLM product (provider abstraction, streaming state management, and typed structured output) into a library maintained by a team that ships breaking-change releases roughly twice a year to keep pace with how fast the underlying model APIs move. That cadence is also the honest caveat: a toolkit moving this fast means documentation, blog posts, and even parts of this article will age within months, so treat version numbers and API shapes as a starting point to verify against the current official docs, not a permanent reference.
FAQ
Q: Is the Vercel AI SDK only for Next.js? A: No. It runs in any TypeScript runtime, including Node, Bun, Deno, and edge functions like Cloudflare Workers, and ships dedicated UI hooks for React, Svelte, Vue, and Angular. Next.js is the most common pairing because Vercel builds both, but it is not a requirement.
Q: Does it support Claude, Gemini, and open-source models? A: Yes. Official provider packages exist for Anthropic, OpenAI, Google, Mistral, xAI, Meta, Perplexity, DeepSeek, and Moonshot, among others, covering over 100 models across 19-plus providers. Any OpenAI-compatible endpoint also works, which covers most self-hosted open-source models served through vLLM or Ollama.
Q: What's the difference between v4, v5, and v6?
A: v5 (July 2025) split UI messages from model messages, moved streaming onto native SSE, renamed tool fields to inputSchema/outputSchema, and added stopWhen/prepareStep loop controls. v6 (December 2025) added a reusable Agent/ToolLoopAgent class, human-in-the-loop tool approval, stable MCP support, and provider-specific tools from Anthropic, OpenAI, Google, and xAI, while staying backward compatible with v5.
Q: Is the Vercel AI SDK free? A: The SDK itself is Apache 2.0 licensed and free to use. You pay the underlying LLM providers directly for tokens. Vercel's optional AI Gateway adds a $5 monthly free credit per team plus pay-as-you-go pricing at provider list price with no markup, and two small paid add-ons for zero-data-retention and provider allowlisting.
Q: How does it compare to LangChain? A: The Vercel AI SDK is lighter, TypeScript-first, and built around web-app streaming UI. LangChain offers more built-in chains, a larger integration catalog, and is generally favored for complex retrieval and multi-agent orchestration. A common production pattern runs the AI SDK on the frontend for chat UI while LangChain or LangGraph handles backend orchestration.
Q: Can I use it without React?
A: Yes. The core generateText, streamText, generateObject, and streamObject functions are framework-agnostic and work in plain Node or edge functions. The useChat/useCompletion hooks are an optional UI layer for React, Svelte, Vue, or Angular.
Q: What is the Agent class in AI SDK 6, and do I need it?
A: ToolLoopAgent lets you define a model, its instructions, and its tools once and reuse that configuration across your app, instead of repeating the same setup inline at every generateText call. It's optional — the underlying generateText/tool() primitives still work directly — but it's useful once you have more than one route or feature calling the same agent configuration.
Q: Does the Vercel AI SDK require using Vercel's AI Gateway or hosting?
A: No. You can supply your own provider API keys directly to the provider helpers (anthropic(), openai(), and so on) and deploy anywhere that runs Node or an edge runtime. The Gateway and Vercel hosting are both optional, separately priced services.
Q: How does structured output with generateObject handle a model that returns malformed JSON?
A: The SDK validates the response against your Zod schema and automatically retries the generation call when parsing or validation fails, rather than surfacing a broken object to your application code. This is one of the more concrete reliability wins over hand-rolled JSON extraction from a plain-text model response.
Q: What's new for tool calling specifically in AI SDK 6?
A: A needsApproval flag on tool definitions enables human-in-the-loop gating, so an agent can pause and wait for explicit approval before executing a sensitive action like sending a message or making a payment, rather than running the tool automatically inside the loop.
Sources
- Vercel: AI SDK 5 release notes — architecture changes, breaking changes, release date
- Vercel: AI SDK 6 release notes — Agent abstraction, MCP support, provider tools
- AI SDK official docs and provider catalog (ai-sdk.dev) — supported providers, frameworks, weekly download figures
- Vercel AI Gateway pricing documentation — free credits, pay-as-you-go model, add-on fees
- AWS: Vercel case study — named customers and Bedrock integration
- GitHub:
vercel/airepository release history - npm package registry:
ai
Follow new articles
Add SciHub101 to your feed reader to see new science and technology stories.
About the Author
SciHub101 is an independent science and technology publication founded and edited by Buğra Sözeri, a software engineer and app developer based in Türkiye. AI tools assist with drafting and research. Source documentation in the existing archive is uneven, and articles are being reviewed and corrected. The Editorial Team byline identifies editorial responsibility; it does not certify specialist or independent human review. Where we compare products, anything built by our own team is labelled as such — see the editorial guidelines and About page for how corrections and disclosures work.
Related Articles

OpenAI o3 Explained — The Reasoning Model
OpenAI o3 explained: how the reasoning model works, what its ARC-AGI, GPQA and FrontierMath scores mean, what it costs, and where its limits are.

Claude 4 Explained — Opus and Sonnet 2025
Claude 4 family explained: Opus 4, Sonnet 4, Haiku 4. Benchmarks, pricing, extended thinking, tool use, and how it compares to GPT-5 and Gemini.

Tool Use vs Agent — What's the Difference?
Tool use lets an LLM call one function. An agent runs a loop of reasoning and tool calls until done. Here's the real distinction.

AI Agents Explained — How Autonomous AI Systems Actually Work
AI agents combine LLMs, tools, memory, and planning to complete multi-step tasks without human input at each step. Architecture, frameworks, real uses, and risks in 2026.

CrewAI vs LangGraph vs AutoGen Compared
CrewAI, LangGraph, and AutoGen compared across abstraction level, state management, production readiness, and multi-agent support for 2026.

Next.js 15: The Developer's Guide to App Router, Server Components, and Turbopack
Next.js 15 shipped in October 2024 and made the App Router the official default for new projects, stabilized Turbopack for development builds, and introduced async request APIs that changed how developers access cookies, headers, and search parameters. Next.js 16 (October 2025) extended Turbopack to production. This guide covers the concepts, architecture decisions, and practical trade-offs of the Next.js 15 era, which remains the most widely deployed major version.