Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vercel AI SDK for building AI-powered applications with streaming, tool calling, and multi-provider support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/ai-gateway.md
1---2title: Vercel AI Gateway3description: Reference for using Vercel AI Gateway with the AI SDK.4---56# Vercel AI Gateway78The Vercel AI Gateway is the fastest way to get started with the AI SDK. It provides access to models from OpenAI, Anthropic, Google, and other providers through a single API.910## Authentication1112Authenticate with OIDC (for Vercel deployments) or an [AI Gateway API key](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway%2Fapi-keys&title=AI+Gateway+API+Keys):1314```env filename=".env.local"15AI_GATEWAY_API_KEY=your_api_key_here16```1718## Usage1920The AI Gateway is the default global provider, so you can access models using a simple string:2122```ts23import { generateText } from 'ai';2425const { text } = await generateText({26model: 'anthropic/claude-sonnet-4.5',27prompt: 'What is love?',28});29```3031You can also explicitly import and use the gateway provider:3233```ts34// Option 1: Import from 'ai' package (included by default)35import { gateway } from 'ai';36model: gateway('anthropic/claude-sonnet-4.5');3738// Option 2: Install and import from '@ai-sdk/gateway' package39import { gateway } from '@ai-sdk/gateway';40model: gateway('anthropic/claude-sonnet-4.5');41```4243## Find Available Models4445**Important**: Always fetch the current model list before writing code. Never use model IDs from memory - they may be outdated.4647List all available models through the gateway API:4849```bash50curl https://ai-gateway.vercel.sh/v1/models51```5253Filter by provider using `jq`. **Do not truncate with `head`** - always fetch the full list to find the latest models:5455```bash56# Anthropic models57curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("anthropic/")) | .id] | reverse | .[]'5859# OpenAI models60curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("openai/")) | .id] | reverse | .[]'6162# Google models63curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("google/")) | .id] | reverse | .[]'64```6566When multiple versions of a model exist, use the one with the highest version number (e.g., prefer `anthropic/claude-sonnet-4.6` over `anthropic/claude-sonnet-4.5` over `claude-sonnet-4`).67