What Is Vercel AI SDK?
Vercel AI SDK is an open-source TypeScript library — installed as npm install ai — that standardizes how you talk to large language models from any JavaScript runtime. It abstracts over OpenAI, Anthropic, Google, Bedrock, Mistral, Groq, and 20+ other providers with one consistent API, so a model swap is a one-line change instead of a rewrite.
It is built around three layers. AI SDK Core gives you generateText, streamText, generateObject, and streamObject — the primitives for chat, streaming, tool use, and structured output. AI SDK UI gives you useChat, useCompletion, and useObject hooks for React, Svelte, and Vue that turn a streaming endpoint into a working chat UI. AI SDK RSC (React Server Components) lets the model stream UI components as part of its response.
What makes it popular with startups is that it does just enough. There is no chain abstraction to learn, no agent graph, no vector store built in — only the model primitives you need, done well, with first-class streaming and typed structured output. You layer the rest (RAG, memory, orchestration) in whatever way fits your product.
It runs anywhere TypeScript runs: Next.js App Router, Node.js, Bun, Deno, Cloudflare Workers, AWS Lambda, Vercel Edge Runtime, Hono, Express. It has become the de facto toolkit for shipping AI features in the JavaScript ecosystem, and understanding its patterns is table stakes for any full-stack engineer adding AI to a product in 2026.
How to Calculate Better Results with vercel ai sdk typescript streaming tool calling agent
Install the core package plus the providers you want: npm install ai @ai-sdk/openai @ai-sdk/anthropic zod. You can start with one provider and add more later without changing your call sites.
For a streaming chat endpoint in Next.js App Router, export a POST handler that returns streamText({ model: openai("gpt-4o"), messages }).toDataStreamResponse(). That is the entire server side.
On the client, import { useChat } from "ai/react", call const { messages, input, handleSubmit } = useChat({ api: "/api/chat" }), and render. You now have a streaming chat UI in ~30 lines of code total.
Graduate to tools: pass a tools object to streamText where each tool has a Zod parameters schema and an execute function. Set maxToolRoundtrips: 5 and the model will call tools, read their results, and continue reasoning — the core of an agent loop.
Treat this page as a decision map. Build a shortlist fast, then run a focused second pass for security, ownership, and operational fit.
When a team keeps one shared selection rubric, tool adoption speeds up because evaluators stop debating criteria every time a new option appears.
Worked Examples
Shipping a streaming chat feature to production
- npm install ai @ai-sdk/openai in an existing Next.js project
- Create app/api/chat/route.ts with a POST handler that calls streamText and returns toDataStreamResponse()
- Create app/chat/page.tsx client component using the useChat hook
- Wire up a textarea and button that call handleSubmit, and map over messages to render
- Deploy to Vercel; streaming works out-of-the-box on the Edge Runtime
- Add rate limiting with @upstash/ratelimit before the streamText call
Outcome: A production-grade streaming chat feature delivered in a single afternoon, with ~60 lines of code total and no commitment to a specific model provider.
Replacing a brittle JSON prompt with generateObject
- Existing code asks GPT-4 for JSON and parses it with try/catch, failing ~5% of the time
- Define a Zod schema: z.object({ summary: z.string(), tags: z.array(z.string()), sentiment: z.enum(["pos","neg","neu"]) })
- Replace the old call with generateObject({ model, schema, prompt })
- The SDK retries automatically when the model returns invalid JSON and coerces the result to the schema
- Delete the try/catch and the manual JSON parsing
- Failure rate in production drops from 5% to under 0.2%
Outcome: A flaky JSON-parsing path becomes a type-safe generateObject call, cutting error rate ~25x while removing a chunk of custom parsing code.
Frequently Asked Questions
What is the Vercel AI SDK?
Vercel AI SDK is an open-source TypeScript toolkit by Vercel for building AI-powered applications. It ships three layers: AI SDK Core (provider-agnostic generateText, streamText, generateObject, streamObject), AI SDK UI (React / Svelte / Vue hooks like useChat and useCompletion), and AI SDK RSC (React Server Components helpers). It installs as a single package: npm install ai.
Which model providers does it support?
First-party providers include OpenAI, Anthropic, Google (Gemini & Vertex), Amazon Bedrock, Azure OpenAI, Mistral, Groq, Cohere, Fireworks, Together, Perplexity, and more. Each provider is a separate package (e.g. @ai-sdk/openai, @ai-sdk/anthropic) you install alongside ai. Community providers cover OpenRouter, Ollama, local llama.cpp, and others.
How is it different from LangChain?
The Vercel AI SDK is deliberately narrower: it standardizes model I/O, streaming, tool calls, and structured output — and stops there. LangChain bundles retrieval, memory, chains, and agents. For a Next.js app that needs streaming chat with tool use, the AI SDK is usually simpler and faster to ship. For complex multi-step RAG pipelines, LangChain or LangGraph may fit better.
Does it support tool calling and structured output?
Yes. generateText and streamText accept a tools object where each tool has a Zod schema for parameters and an execute function. generateObject and streamObject produce type-safe JSON matching a Zod schema — the SDK handles retries and repairs automatically when the model returns invalid JSON.
Can I build agents with it?
Yes. The SDK exposes a maxSteps (now maxToolRoundtrips) option and an experimental_continueSteps API that lets the model call tools, read their results, and continue reasoning in a loop until it either answers or hits the step budget. For more opinionated agent patterns, pair it with a dedicated agent framework or build your own orchestrator around streamText.
Does it work outside Vercel / Next.js?
Yes. AI SDK Core has no framework dependency — you can use it in plain Node.js, Bun, Deno, Cloudflare Workers, AWS Lambda, or Hono. AI SDK UI is framework-specific (hooks for React, Svelte, Vue). RSC helpers require a React Server Components-capable setup like Next.js App Router.