New skills (14): - nestjs-best-practices: 40 priority-ranked rules (kadajett) - fastapi: Pydantic v2, async SQLAlchemy, JWT auth (jezweb) - architecture-patterns: Clean Architecture, Hexagonal, DDD (wshobson) - python-performance-optimization: Profiling and optimization (wshobson) - ai-sdk: Vercel AI SDK streaming and agent patterns (vercel) - create-agent: Modular agent architecture with OpenRouter (openrouterteam) - proactive-agent: WAL Protocol, compaction recovery, self-improvement (halthelobster) - brand-guidelines: Brand identity enforcement (anthropics) - ui-animation: Motion design with accessibility (mblode) - marketing-ideas: 139 ideas across 14 categories (coreyhaines31) - pricing-strategy: SaaS pricing and tier design (coreyhaines31) - programmatic-seo: SEO at scale with playbooks (coreyhaines31) - competitor-alternatives: Comparison page architecture (coreyhaines31) - referral-program: Referral and affiliate programs (coreyhaines31) README reorganized by domain: Code Quality, Frontend, Backend, Auth, AI/Agent Building, Marketing, Design, Meta. Mosaic Stack is not limited to coding — the Orchestrator serves coding, business, design, marketing, writing, logistics, and analysis. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
67 lines
2.1 KiB
Markdown
67 lines
2.1 KiB
Markdown
---
|
|
title: Vercel AI Gateway
|
|
description: Reference for using Vercel AI Gateway with the AI SDK.
|
|
---
|
|
|
|
# Vercel AI Gateway
|
|
|
|
The 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.
|
|
|
|
## Authentication
|
|
|
|
Authenticate 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):
|
|
|
|
```env filename=".env.local"
|
|
AI_GATEWAY_API_KEY=your_api_key_here
|
|
```
|
|
|
|
## Usage
|
|
|
|
The AI Gateway is the default global provider, so you can access models using a simple string:
|
|
|
|
```ts
|
|
import { generateText } from 'ai';
|
|
|
|
const { text } = await generateText({
|
|
model: 'anthropic/claude-sonnet-4.5',
|
|
prompt: 'What is love?',
|
|
});
|
|
```
|
|
|
|
You can also explicitly import and use the gateway provider:
|
|
|
|
```ts
|
|
// Option 1: Import from 'ai' package (included by default)
|
|
import { gateway } from 'ai';
|
|
model: gateway('anthropic/claude-sonnet-4.5');
|
|
|
|
// Option 2: Install and import from '@ai-sdk/gateway' package
|
|
import { gateway } from '@ai-sdk/gateway';
|
|
model: gateway('anthropic/claude-sonnet-4.5');
|
|
```
|
|
|
|
## Find Available Models
|
|
|
|
**Important**: Always fetch the current model list before writing code. Never use model IDs from memory - they may be outdated.
|
|
|
|
List all available models through the gateway API:
|
|
|
|
```bash
|
|
curl https://ai-gateway.vercel.sh/v1/models
|
|
```
|
|
|
|
Filter by provider using `jq`. **Do not truncate with `head`** - always fetch the full list to find the latest models:
|
|
|
|
```bash
|
|
# Anthropic models
|
|
curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("anthropic/")) | .id] | reverse | .[]'
|
|
|
|
# OpenAI models
|
|
curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("openai/")) | .id] | reverse | .[]'
|
|
|
|
# Google models
|
|
curl -s https://ai-gateway.vercel.sh/v1/models | jq -r '[.data[] | select(.id | startswith("google/")) | .id] | reverse | .[]'
|
|
```
|
|
|
|
When multiple versions of a model exist, use the one with the highest version number (e.g., prefer `claude-sonnet-4-5` over `claude-sonnet-4` over `claude-3-5-sonnet`).
|