Skip to Content

Vercel AI Gateway model routing

Vercel AI Gateway routing lets you switch models and providers with minimal code changes — configure fallbacks and provider preferences per request.

Hub: Tokenminning with Vercel AI Gateway. Pattern: Model routing.

AI SDK default to cheap tier

import { generateText } from "ai"; const result = await generateText({ model: "openai/gpt-4o-mini", prompt: "Classify this support ticket.", });

Reserve anthropic/claude-sonnet-4 or openai/gpt-4o for multi-step agent work.

Provider options and fallbacks

Provider options  configure routing, fallbacks, and provider preferences:

import { generateText } from "ai"; const result = await generateText({ model: "anthropic/claude-3-5-haiku-20241022", prompt: "Summarize this log line.", providerOptions: { gateway: { order: ["anthropic", "openai"], }, }, });

Gateway automatically retries on provider failure — you are billed only for the successful attempt.

Tier selection

TaskModel slug
Classification, extractionopenai/gpt-4o-mini, anthropic/claude-3-5-haiku
Agent loopsopenai/gpt-4o, anthropic/claude-sonnet-4
Deep reasoningFrontier — explicit escalation only

Browse models at AI Gateway models .

Spending guardrails

  • Default AI SDK model to mini/haiku in shared config
  • Escalate model tier in code, not by changing defaults globally
  • Log model slug per request in your observability stack
  • Avoid web-search-augmented models unless the task requires live data
Last updated on