AI Gateway
AI Gateway is available on all plans and your use is subject to AI Product Terms.
The AI Gateway provides a unified API to access hundreds of models through a single endpoint. It gives you the ability to set budgets, monitor usage, load-balance requests, and manage fallbacks.
The design allows it to work seamlessly with AI SDK 5, OpenAI SDK, or your preferred framework.
- Unified API: helps you switch between providers and models with minimal code changes
- High Reliability: automatically retries requests to other providers if one fails
- Embeddings Support: generate vector embeddings for search, retrieval, and other tasks
- Spend Monitoring: monitor your spending across different providers
index.ts
import { generateText } from 'ai';
const { text } = generateText({
model: 'anthropic/claude-sonnet-4',
prompt: 'What is the capital of France?',
});
index.py
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv('AI_GATEWAY_API_KEY'),
base_url='https://ai-gateway.vercel.sh/v1'
)
response = client.chat.completions.create(
model='xai/grok-4',
messages=[
{
'role': 'user',
'content': 'Why is the sky blue?'
}
]
)
index.sh
curl -X POST "https://ai-gateway.vercel.sh/v1/chat/completions" \
-H "Authorization: Bearer $AI_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
],
"stream": false
}'
Was this helpful?