Build AI agents with hundreds of models
vercel ai-gateway coding-agents setupimport { ToolLoopAgent, tool } from 'ai';
import { z } from 'zod';
const agent = new ToolLoopAgent({
model: 'anthropic/claude-sonnet-5',
tools: {
getWeather: tool({
description: 'Get the current weather for a location',
inputSchema: z.object({ location: z.string() }),
execute: async ({ location }) => ({
location,
temperature: 72,
condition: 'sunny',
}),
}),
},
});
const { text } = await agent.generate({
prompt: "What's the weather in Tokyo?",
});
console.log(text);curl https://ai-gateway.vercel.sh/v1/chat/completions \
-H "Authorization: Bearer $AI_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-6-astra",
"messages": [
{
"role": "user",
"content": "Invent a new holiday and describe its traditions."
}
]
}'AI Gateway is available on all plans . Your use of each AI provider is subject to their terms listed on each model's page and subject to Vercel's AI Product Terms.
AI Gateway works with the AI SDK, OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, or your preferred framework.
Send images, files, audio, and video to compatible models, or connect them to application functions with tool use.
- One key, hundreds of models. Access models from multiple providers with a single API key
- Unified API. 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
- No markup on tokens. Tokens cost the same as they would from the provider directly, with zero markup, including with Bring Your Own Key (BYOK)
- AI Gateway pricing: Understand token costs, credits, add-on charges, and payment fees.
- Budgets and spend limits: Set spending limits and alerts for teams, projects, API keys, and users.
- Rate limits: Understand request limits and handle
429responses. - Security and compliance: Configure data retention, prompt training policies, and model and provider access.
Use the resources below to configure AI Gateway, or browse the AI Gateway guides for implementation patterns, templates, and troubleshooting.
Getting started
Make your first request to AI Gateway with the AI SDK.
Models and providers
Browse hundreds of models from leading providers.
Provider options
Configure routing, fallbacks, and provider preferences.
Web search
Augment model responses with real-time web search.
Observability
Monitor usage, latency, and spend across providers.
Coding Agents
Build coding agents on top of AI Gateway.
Anthropic compatibility
Use the Anthropic Messages API through AI Gateway.
OpenAI compatibility
Use the OpenAI Chat Completions API through AI Gateway.
Disallow prompt training
Control whether your prompts can be used for training.
Usage and billing
Understand pricing, usage metrics, and billing.
Authentication
Authenticate requests with API keys or OIDC tokens.
Bring your own key
Use your own provider keys with AI Gateway.
Framework integrations
Use AI Gateway with your preferred framework.
App attribution
Track which apps are making requests through AI Gateway.
Was this helpful?