Skip to Content

Build AI agents

Build an agent

}, tools: {

import { ToolLoopAgent, tool } from'ai';

Build an agent
  • constagent=newToolLoopAgent({
  • getWeather:tool({
  • import { z } from'zod';
  • temperature:72,

}),

location, });

description:'Get the current weather for a location',

Generate text
  • Generate structured data
  • execute:async ({ location }) => ({
  • const { text } =awaitagent.generate({
  • model:'anthropic/claude-fable-5.1',
  • condition:'sunny',

Add models, tools, and streaming

At the center of the AI SDK is AI SDK Core, which provides a unified API to call any LLM.

Generating text

  • Unified provider API. Switch between models by changing two lines of code
  • Structured outputs. Generate type-safe JSON with generateObject and streamObject
  • Tool calling. Let models interact with external systems
  • Streaming first. Stream text, objects, and UI to your frontend
  • Framework support. Works with React, Next.js, Vue, Svelte, and Node.js
import { generateText } from'ai';
Paid ads
prompt:'Explain the concept of quantum entanglement.',
The following example shows how to generate text with the AI SDK using OpenAI's GPT-6 Astra:

});

import { generateText } from'ai';

const { text } =awaitgenerateText({
The unified interface lets you switch providers by changing the model string. For example, to use Anthropic's Claude Fable 5.1:
model:'openai/gpt-6-astra',
prompt:'How many people will live in the world in 2040?',

Generating structured data

While text generation can be useful, you might want to generate structured JSON data. For example, you might want to extract information from text, classify data, or generate synthetic data. AI SDK Core provides two functions ( generateObject and streamObject) to generate structured data, allowing you to constrain model outputs to a specific schema.

});
model:'anthropic/claude-fable-5.1',
const { text } =awaitgenerateText({
The following example shows how to generate a type-safe recipe that conforms to a zod schema:

recipe:z.object({

schema:z.object({

model:'openai/gpt-6-astra',

const { object } =awaitgenerateObject({

import { z } from'zod';

ingredients:z.array(z.object({ name:z.string(), amount:z.string() })),

}),

}),

name:z.string(),

steps:z.array(z.string()),

import { generateObject } from'ai';

prompt:'Generate a lasagna recipe.',

Give agents tools

The AI SDK supports tool calling out of the box, allowing it to interact with external systems and perform discrete tasks. The following example shows how to use tool calling with the AI SDK:


Our Services

prompt:'What is the weather like today in San Francisco?',

tools: {

location:z.string().describe('The location to get the weather for'),

const { text } =awaitgenerateText({
}),
import { generateText, tool } from'ai';
location,

Brand & Design

}),

model:'openai/gpt-6-astra',
getWeather:tool({
execute:async ({ location }) => ({
description:'Get the weather in a location',

}),

temperature:72+Math.floor(Math.random() *21) -10,

});
inputSchema:z.object({
import { z } from'zod';
},

Getting started with the AI SDK

See the AI SDK Getting Started guide for more information on how to get started with the AI SDK.

Use Vercel Connect with AI SDK

Vercel Connect supplies short-lived OAuth tokens to MCP clients built with AI SDK, so models can call tools from services such as Linear without storing provider credentials in your application. The connectAuthProvider() helper requests credentials and supports user consent flows.

bun
pnpm
The AI SDK is available as a package. To install it, run the following command:
yarn

Use Jev with AI SDK

Learn how to classify, route, and score with Jev and AI SDK, or follow Route form submissions with Jev and AI SDK to build a form router with configurable destinations and a fallback model for uncertain decisions.

npm
Follow Build AI agents with AI Gateway and AI SDK to set up authentication, stream responses, and add tools and model fallbacks.
pnpm i ai
Follow the AI SDK and MCP tutorial to configure Vercel Connect, make MCP tools available to an AI SDK application, and handle tool approval.

Build with a template

Jev, an evaluation model from TypeSafe AI, returns typed choices, scores, and boolean probabilities that your application can use to classify requests, route work, and assess proposed actions. Call Jev through AI Gateway with the experimental evaluate API in AI SDK 7 or later.

Integrations
Start with an AI SDK template to build a chatbot or route form submissions with Jev:
Maintenance

Cross-link map: AI SDK (/docs/ai-sdk)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesAI SDK with AI Gateway — Build AI-powered TypeScript applications using the AI SDK with AI Gateway for unified access to 200+ models.AI SDK for Python with AI Gateway — Build AI-powered Python applications using the AI SDK for Python with AI Gateway for unified access to 200+ models.ToolsAI SDK by VercelVercel AI SDK 3.1: ModelFusion joins the teamThis page links to (4)OverviewGetting StartedAI SDK and MCP — Connect an AI SDK app to an OAuth-protected MCP server with Vercel Connect, then handle user consent and tool approval.Build AI agents with AI Gateway and AI SDK — Build AI agents on Vercel with AI Gateway and AI SDK, then make them reliable, capable, and durable with Sandbox, Chat SPages that link here (9)By site: vercel-kb (1) · vercel-web (2) · vercel-docs (6)From vercel-kbHow to architect an AI evaluation dashboard on Vercel — Map eval orchestration, traces, and run storage to AI Gateway, Observability, and Marketplace Postgres, and learn when sFrom vercel-webAgentic InfrastructureZero Data Retention on AI GatewayFrom vercel-docsAI Gateway Framework Integrations — Connect LangChain, LiteLLM, LlamaIndex, Mastra, Pydantic AI, TanStack AI, and other frameworks to Vercel AI Gateway withMastra with AI Gateway — Learn how to integrate Vercel AI Gateway with Mastra to access multiple AI models through a unified interface.Glossary — Learn about the terms and concepts used in Vercel's products and documentation.AI SDK with MCP — Connect the AI SDK to an MCP server on Vercel, discover its tools, and call them with models served through AI Gateway.Products — Browse Vercel products for building, deploying, securing, observing, and scaling web applications.Projects overview — A project is where you deploy and operate frontend apps, APIs, backends, containers, and agent workloads on Vercel.

MCP

You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.

We’re committed to providing prompt and effective solutions to ensure your satisfaction.

We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.