Skip to main content

Installation

The AI SDK is available as npm packages. You can install the core SDK and optional provider packages based on your needs.

Requirements

Before you begin, ensure you have:
  • Node.js: Version 18 or higher
  • Package manager: npm, pnpm, yarn, or bun

Install the core SDK

The ai package contains the core SDK functionality including generateText, streamText, and other core APIs:

Choose a provider

You have two options for accessing AI models: The Vercel AI Gateway provides access to hundreds of models from different providers with a single API key. The gateway provider is included in the ai package by default.
1

Get an API key

2

Add to environment

Create a .env.local file in your project root:
Add your API key:
3

Start using models

You can now access any model using a simple string:

Option 2: Direct provider packages

Install specific provider packages to connect directly to AI services:
Then configure your provider credentials:
Use the provider in your code:

Framework-specific packages

If you’re building chat or generative UI applications, install the framework integration for your UI library:
These packages provide hooks and utilities for building chat interfaces:

Additional packages

Depending on your use case, you may need additional packages:

Schema validation

For structured outputs and tool definitions, install Zod:

Next.js RSC (React Server Components)

For Next.js applications using React Server Components:

Verify installation

Create a simple test file to verify your installation:
Run the file:
Make sure you’ve set up your API keys in the .env.local file before running the test.

TypeScript configuration

The AI SDK is written in TypeScript and provides full type safety. Ensure your tsconfig.json includes:

Next steps

Quickstart

Build your first AI application

Providers

Learn about available AI providers

AI SDK Core

Explore core functions and APIs

AI SDK UI

Build chat and generative interfaces