Skip to main content

AI SDK by Vercel

The AI SDK is the TypeScript toolkit designed to help developers build AI-powered applications and agents with React, Next.js, Vue, Svelte, Node.js, and more.

Installation

Get started by installing the AI SDK in your project

Quickstart

Build your first AI application in minutes

AI SDK Core

Generate text, structured objects, and build agents with LLMs

AI SDK UI

Framework-agnostic hooks for chat and generative interfaces

Why use the AI SDK?

Integrating large language models (LLMs) into applications is complicated and heavily dependent on the specific model provider you use. The AI SDK standardizes integrating artificial intelligence (AI) models across supported providers. This enables developers to focus on building great AI applications, not waste time on technical details.

Unified API across providers

Switch between different AI providers with minimal code changes. The AI SDK provides a consistent interface whether you’re using OpenAI, Anthropic, Google, or other providers:
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { anthropic } from '@ai-sdk/anthropic';

// Use OpenAI
const result1 = await generateText({
  model: openai('gpt-4o'),
  prompt: 'What is an agent?',
});

// Switch to Anthropic with the same code structure
const result2 = await generateText({
  model: anthropic('claude-sonnet-4-5'),
  prompt: 'What is an agent?',
});

Or use Vercel AI Gateway

The Vercel AI Gateway provides instant access to all major providers with a single API key:
import { generateText } from 'ai';

// Access any model with a simple string
const result = await generateText({
  model: 'openai/gpt-4o',
  prompt: 'What is an agent?',
});

Core capabilities

The AI SDK has two main libraries:

AI SDK Core

A unified API for generating text, structured objects, tool calls, and building agents with LLMs.

AI SDK UI

Framework-agnostic hooks for quickly building chat and generative user interfaces.

Generate text

Generate text completions with streaming support:
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const { text } = await generateText({
  model: openai('gpt-4o'),
  prompt: 'What is an agent?',
});

Generate structured data

Generate type-safe structured outputs using Zod schemas:
import { generateText, Output } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const { output } = await generateText({
  model: openai('gpt-4o'),
  output: Output.object({
    schema: z.object({
      recipe: z.object({
        name: z.string(),
        ingredients: z.array(
          z.object({ name: z.string(), amount: z.string() })
        ),
        steps: z.array(z.string()),
      }),
    }),
  }),
  prompt: 'Generate a lasagna recipe.',
});

Build agents with tools

Create agents that can use tools to accomplish tasks:
import { generateText, tool } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: {
    weather: tool({
      inputSchema: z.object({
        location: z.string(),
      }),
      execute: async ({ location }) => {
        // Call weather API
        return { temperature: 72, condition: 'sunny' };
      },
    }),
  },
  prompt: 'What is the weather in San Francisco?',
});

Stream text and UI

Stream responses for real-time user interfaces:
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';

const result = streamText({
  model: openai('gpt-4o'),
  prompt: 'Invent a new holiday and describe its traditions.',
});

for await (const chunk of result.textStream) {
  console.log(chunk);
}

Supported providers

The AI SDK supports multiple model providers out of the box:

OpenAI

GPT-4o, GPT-4, GPT-3.5 Turbo

Anthropic

Claude 4.5, Claude 3.5 Sonnet

Google

Gemini 2.5 Flash, Gemini Pro

Mistral

Mistral Large, Mistral Medium

Meta

Llama 3.3, Llama 3.1

And more

Amazon Bedrock, Azure, Cohere, and custom providers

Framework integrations

Build AI applications with your favorite framework:

Next.js

React Server Components and App Router support

React

Hooks for building chat interfaces

Vue

Composables for Vue 3 applications

Svelte

Stores and utilities for Svelte apps

Node.js

Express, Fastify, and native HTTP support

Angular

Services for Angular applications

Next steps

Install the SDK

Set up the AI SDK in your project

Build your first app

Follow the quickstart guide

Explore providers

Learn about available AI providers

API reference

Dive into the complete API documentation

Join our community

If you have questions about anything related to the AI SDK, you’re always welcome to ask our community on the Vercel Community.