AI Gateway Provider Options
AI Gateway can route your AI model requests across multiple AI providers. Each provider offers different models, pricing, and performance characteristics. By default, AI Gateway will automatically choose providers for you to ensure fast and dependable responses.
With the Gateway Provider Options, you can control the routing order and fallback behavior of the models.
If you want to customize individual AI model provider settings rather than general gateway behavior, please refer to the model-specific provider options in the AI SDK documentation.
You can use the order
array to specify the sequence in which providers should be attempted. Providers are specified using their slug
string. You can find the slugs in the table of available providers.
You can also copy the provider slug using the copy button next to a provider's name on a model's detail page. In the Vercel Dashboard:
- Click the AI Gateway tab,
- Then, click the Model List sub-tab on the left
- Click a model entry in the list.
The bottom section of the page lists the available providers for that model. The copy button next to a provider's name will copy their slug for pasting.
First, ensure you have the necessary package installed:
terminalpnpm install ai
Use the
providerOptions.gateway.order
configuration:app/api/chat/route.tsimport { streamText } from 'ai'; export async function POST(request: Request) { const { prompt } = await request.json(); const result = streamText({ model: 'anthropic/claude-4-sonnet', prompt, providerOptions: { gateway: { order: ['bedrock', 'anthropic'], // Try Amazon Bedrock first, then Anthropic }, }, }); return result.toUIMessageStreamResponse(); }
In this example:
- The gateway will first attempt to use Amazon Bedrock to serve the Claude 4 Sonnet model
- If Amazon Bedrock is unavailable or fails, it will fall back to Anthropic
- Other providers (like Vertex AI) are still available but will only be used after the specified providers
You can monitor which provider you used by checking the provider metadata in the response.
app/api/chat/route.tsimport { streamText } from 'ai'; export async function POST(request: Request) { const { prompt } = await request.json(); const result = streamText({ model: 'anthropic/claude-4-sonnet', prompt, providerOptions: { gateway: { order: ['bedrock', 'anthropic'], }, }, }); // Log which provider was actually used console.log(JSON.stringify(await result.providerMetadata, null, 2)); return result.toUIMessageStreamResponse(); }
You can combine gateway provider options with provider-specific options. This allows you to control both the routing behavior and provider-specific settings in the same request:
import { streamText } from 'ai';
export async function POST(request: Request) {
const { prompt } = await request.json();
const result = streamText({
model: 'anthropic/claude-4-sonnet',
prompt,
providerOptions: {
anthropic: {
thinkingBudget: 0.001,
},
gateway: {
order: ['bedrock'],
},
},
});
return result.toUIMessageStreamResponse();
}
In this example:
- We're using an Anthropic model (e.g. Claude 4 Sonnet) but accessing it through Bedrock
- The Anthropic-specific options still apply to the model:
thinkingBudget
sets a cost limit of $0.001 per request for the Claude model
- You can read more about provider-specific options in the AI SDK documentation
You can view the available models for a provider in the Model List section under the AI Gateway tab in your Vercel dashboard.
Slug | Name | Website |
---|---|---|
anthropic | Anthropic | anthropic.com |
bedrock | Amazon Bedrock | aws.amazon.com/bedrock |
cerebras | Cerebras | cerebras.net |
cohere | Cohere | cohere.com |
deepinfra | DeepInfra | deepinfra.com |
deepseek | DeepSeek | deepseek.ai |
fireworks | Fireworks | fireworks.ai |
groq | Groq | groq.com |
inception | Inception | inceptionlabs.ai |
mistral | Mistral | mistral.ai |
moonshotai | Moonshot AI | moonshot.ai |
morph | Morph | morphllm.com |
openai | OpenAI | openai.com |
parasail | Parasail | parasail.com |
perplexity | Perplexity | perplexity.ai |
vertex | Vertex AI | cloud.google.com/vertex-ai |
xai | xAI | x.ai |
Provider availability may vary by model. Some models may only be available through specific providers or may have different capabilities depending on the provider used.
Was this helpful?