Get Your API Key

AI Gateway

The Vercel AI Gateway is the fastest way to get started with the AI SDK. Access models from OpenAI, Anthropic, Google, and other providers without having to manage multiple API keys. Authenticate with an AI Gateway API key or OIDC.

Add your API key to your environment:

.env.local
AI_GATEWAY_API_KEY=your_api_key_here

The AI Gateway is the default global provider, so you can access models using a plain string. The AI Gateway references models as creator/model.

You can view the model list to find all models currently available in the gateway in the exact string format. You can directly copy the respective string from the list and use it. The names may differ slightly from the model ID syntax from providers that have the same model. You can also use your editor's autocomplete to lookup these strings.

import { generateText } from 'ai';
const { text } = await generateText({
model: 'anthropic/claude-sonnet-4.5',
prompt: 'What is love?',
});

Another option is to explicitly import and use the Gateway provider with the model slug.

import { gateway } from '@ai-sdk/gateway';
model: gateway('anthropic/claude-sonnet-4.5');

Using Dedicated Providers

You can also use first-party, OpenAI-compatible, and community provider packages directly. Install the package and create a provider instance. For example, to use Anthropic:

pnpm add @ai-sdk/anthropic@beta
import { anthropic } from '@ai-sdk/anthropic';
model: anthropic('claude-sonnet-4-5');

You can change the default global provider so string model references use your preferred provider everywhere in your application. Learn more about provider management.

See available providers for setup instructions for each provider.

Custom Providers

You can build your own provider to integrate any service with the AI SDK. The AI SDK provides a Language Model Specification that ensures compatibility across providers.

import { generateText } from 'ai';
import { yourProvider } from 'your-custom-provider';
const { text } = await generateText({
model: yourProvider('your-model-id'),
prompt: 'What is love?',
});

See Writing a Custom Provider for a complete guide.