Vercel AI SDK

Also known as: AI SDK

On this page 7

The Vercel AI SDK (often shortened to AI SDK) is an open-source TypeScript toolkit for building applications that call large language models, stream their output to a user interface and let them use tools. Among AI frameworks & tools, it occupies the application and web layer: it does not train or host models, but gives JavaScript and TypeScript developers one provider-neutral API for text generation, structured output, embeddings and agent loops.

The library is maintained by Vercel and released under the Apache 2.0 license. It runs in Node.js, edge runtimes and the browser, and it is framework-agnostic, although its most common pairing is a Next.js front end with server-side route handlers.

How the Vercel AI SDK is organized

The AI SDK is split into three cooperating layers, each published as separate packages so that a project installs only what it needs. The core layer runs on the server, the UI layer runs in the browser, and the provider layer translates the common interface into the wire format of each model vendor.

The following table summarizes the layers and the functions developers meet first.

LayerTypical packageKey functionsRuns where
AI SDK CoreaigenerateText, streamText, generateObject, embedServer or edge function
AI SDK UI@ai-sdk/react and siblingsuseChat, useCompletion, useObjectBrowser components
Providers@ai-sdk/openai, @ai-sdk/anthropic and othersModel factory functionsServer, called by Core
Server Components support@ai-sdk/rscstreamUI, streamable valuesReact Server Components
Main layers of the AI SDK

The central idea is the language model specification, an internal interface that every provider package implements. Because application code talks only to that interface, switching vendors usually means changing one import and one model identifier, not rewriting prompts, streaming logic or tool handling.

Streaming, structured output and tool calling

The AI SDK treats streaming as the default interaction pattern, because users perceive a response that appears token by token as far faster than one that arrives after ten seconds of silence. streamText returns an object whose result can be piped directly into an HTTP response using a standardized data stream protocol, which the UI hooks then parse and render incrementally.

For machine-readable results, generateObject and streamObject accept a Zod or JSON Schema definition and ask the model to return data that conforms to it. The SDK validates the result and raises a typed error when the model produces invalid JSON, so schema validation replaces fragile string parsing.

Tool calling works through the tool helper: each tool declares a description, an input schema and an execute function. When the model requests a tool, the SDK runs the function, feeds the result back and, if multi-step execution is enabled through a step limit or a stop condition, lets the model continue until it produces a final answer. This loop is the basis of simple agents built with the AI SDK.

The table below compares the main generation functions by output type and typical use.

FunctionOutputBest suited for
generateTextComplete text and tool resultsBackground jobs, batch processing
streamTextIncremental text and eventsChat interfaces, long answers
generateObjectValidated typed objectExtraction, classification, form filling
streamObjectPartial object updatesProgressively rendered structured views
embed and embedManyNumeric vectorsSemantic search, retrieval pipelines
Core generation functions compared

The AI SDK is best understood as a thin, typed integration layer rather than a full orchestration framework. LangChain and LlamaIndex offer large catalogs of retrievers, document loaders and chain abstractions; the AI SDK deliberately keeps a small surface area and leaves retrieval, memory and data storage to the developer.

This comparison shows where it sits next to neighboring tools in the same field.

ToolPrimary languageMain focusTypical choice when
Vercel AI SDKTypeScriptStreaming UI, provider abstraction, toolsA web product needs chat or generative UI
LangChainPython and TypeScriptChains, retrieval, integrationsMany data connectors are needed
LangGraphPython and TypeScriptStateful agent graphsAgents need explicit control flow
LiteLLMPythonProxy with a unified model APIA gateway must serve many teams
OpenAI Agents SDKPython and TypeScriptAgents with handoffs and guardrailsWork centers on one vendor’s agent model
Positioning against neighboring tools

The tools are not mutually exclusive. A common architecture uses a LangGraph or Python service for heavy orchestration and the AI SDK UI hooks in the front end, because the data stream protocol can be produced by any backend that follows its format.

Choosing and configuring the AI SDK in practice

Adoption decisions usually depend on the language of the team, the importance of a responsive interface and the number of model vendors involved. The following decision table maps common situations to a recommendation.

SituationRecommendationReason
TypeScript web app with a chat featureUse AI SDK Core and UIHooks handle streaming state and message history
Need to compare several model vendorsUse provider packagesModel swaps need minimal code changes
Python data science stackPrefer a Python frameworkThe SDK targets JavaScript runtimes
Complex long-running agent workflowsCombine with an orchestratorThe built-in loop is intentionally simple
When the AI SDK is a good fit

Production configuration typically adds middleware through wrapLanguageModel for caching, guardrails or logging, sets request timeouts and abort signals, and enables the built-in OpenTelemetry instrumentation so that latency, token usage and tool calls appear in an observability platform such as Langfuse or LangSmith.

Limitations and common mistakes

The AI SDK abstracts differences between providers but cannot remove them. Features such as prompt caching, reasoning controls or file inputs vary by vendor and are often exposed through provider-specific options, so code that relies on them is less portable than the unified interface suggests.

  • Frequent major versions have renamed functions and message formats, so upgrades between majors require reading migration guides and testing carefully.
  • Exposing API keys in client code is a serious error; model calls belong in server routes, with only the stream sent to the browser.
  • Unbounded tool loops can multiply cost and latency; always set a step limit and log every tool call.
  • Trusting structured output blindly is risky, because a schema guarantees shape, not factual correctness.

In everyday language

The Vercel AI SDK is a set of building blocks for web developers. It helps them add an AI assistant to a website or app. Each AI company has its own rules. With this toolkit, a developer writes code once. Later, the developer can swap the underlying model with a small change.

It also handles the part users notice most. Words appear on screen as the AI writes them. It feels like watching someone type a message. Nobody has to wait for a finished block of text.

Seen in the real world

A mid-sized online retailer wants a product-support assistant inside its Next.js storefront. The development team writes one server route that calls streamText with a system prompt, the customer’s message history and two tools: one that looks up order status and one that searches the help center.

On the front end, the useChat hook renders streaming replies and shows a short status line while a tool runs. During testing, the team compares two vendors by changing a single model identifier and selects the one with lower latency at acceptable quality. A step limit of five prevents runaway tool loops.

After launch, OpenTelemetry traces show a median first-token time under one second, and the support queue sees fewer simple order-status questions, because customers now receive answers directly in the chat.