Skip to content
Docs

Build AI agents with hundreds of models

Build agents and AI applications through one API. AI Gateway routes requests, manages fallbacks and budgets, monitors usage, and connects supported coding agents.
terminal
vercel ai-gateway coding-agents setup
agent.ts
import { 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);
terminal
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)

Use the resources below to configure AI Gateway, or browse the AI Gateway guides for implementation patterns, templates, and troubleshooting.


Was this helpful?

supported.