Skip to main content
Version: Next

Connect Vercel AI Gateway

This guide will help you configure Agent Router to route traffic to Vercel AI Gateway, which exposes models from many providers behind a single OpenAI-compatible endpoint at https://ai-gateway.vercel.sh/v1.

Because Vercel AI Gateway speaks the OpenAI Chat Completions API and authenticates with Authorization: Bearer <token>, it is configured with the OpenAI schema and an API key, the same as any other OpenAI-compatible provider. This is useful when you want a single egress and spend-tracking layer for models that are not hosted in your own cluster.

Prerequisites​

Before you begin, you'll need:

Because Vercel AI Gateway fronts many models, the route in this example matches every value of x-ai-eg-model rather than a fixed list. Remove the mock route from the basic setup first so the two do not overlap:

kubectl delete aigatewayroute envoy-ai-gateway-basic

Configuration Steps​

Ready to proceed?

Ensure you have followed the steps in Connect Providers

1. Download configuration template​

curl -O https://raw.githubusercontent.com/theagentrouter/agent-router/main/examples/basic/vercel.yaml

2. Configure Vercel AI Gateway Credentials​

Edit the vercel.yaml file to replace the Vercel placeholder value:

  • Find the section containing VERCEL_AI_GATEWAY_API_KEY
  • Replace it with your actual Vercel AI Gateway API key
Security Note

Make sure to keep your API key secure and never commit it to version control. The key will be stored in a Kubernetes secret.

3. Apply Configuration​

Apply the updated configuration and wait for the Gateway pod to be ready. If you already have a Gateway running, then the secret credential update will be picked up automatically in a few seconds.

kubectl apply -f vercel.yaml

kubectl wait pods --timeout=2m \
-l gateway.envoyproxy.io/owning-gateway-name=envoy-ai-gateway-basic \
-n envoy-gateway-system \
--for=condition=Ready

4. Test the Configuration​

You should have set $GATEWAY_URL as part of the basic setup before connecting to providers. See the Basic Usage page for instructions.

Vercel AI Gateway model IDs follow the creator/model-name format, for example openai/gpt-4o-mini or anthropic/claude-sonnet-4.5. See Models & Providers for the available IDs, or query https://ai-gateway.vercel.sh/v1/models.

Test Chat Completions​

curl -H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Hi."
}
]
}' \
$GATEWAY_URL/v1/chat/completions

Test Embeddings​

curl -H "Content-Type: application/json" \
-d '{
"model": "openai/text-embedding-3-small",
"input": "Agent Router"
}' \
$GATEWAY_URL/v1/embeddings

Using the native Anthropic API​

Vercel AI Gateway also serves the native Anthropic Messages API on the same host. To route to it, configure a second AIServiceBackend with the Anthropic schema and an AnthropicAPIKey BackendSecurityPolicy, which sends the key in the x-api-key header:

spec:
schema:
name: Anthropic

Requests then go to $GATEWAY_URL/anthropic/v1/messages. See Supported Providers for the full schema and authentication matrix.

Troubleshooting​

If you encounter issues:

  1. Verify your API key is correct and active

  2. Check pod status:

    kubectl get pods -n envoy-gateway-system
  3. View controller logs:

    kubectl logs -n envoy-ai-gateway-system deployment/ai-gateway-controller
  4. View External Processor Logs

    kubectl logs -n envoy-gateway-system -l gateway.envoyproxy.io/owning-gateway-name=envoy-ai-gateway-basic -c ai-gateway-extproc
  5. Common errors:

    • 401: Invalid API key
    • 403: The API key's project does not have access to the requested model
    • 429: Rate limit or spend limit exceeded
    • 502: Upstream model provider unavailable