Cloudflare AI Gateway Multi-Provider Routing & Spend Policies
Measured routing behavior, failover latency, and spend-cap economics across Anthropic, Vertex AI, Groq, and Fireworks with exact pricing, headers, and
Cloudflare AI Gateway multi-provider routing defaults on for gateways created after 2026-12-09, routes Claude models across Anthropic and Vertex AI, and enforces hourly/daily/weekly/monthly UTC spend caps via Access-backed policies.
Key Numbers & Verified Specs
6 metrics| Metric / Spec | Verified Finding | Source |
|---|---|---|
| Multi-provider routing default | On by default for gateways created on or after December 9, 2026; off for older gateways until enabled via multiprovider_enabled: true | developers.cloudflare.com |
| Provider order header | cf-aig-provider-order lists preferred providers first; provider order is a preference, not a hard restriction, and unhealthy providers trigger fallback | developers.cloudflare.com |
| Spend cap reset cadence | Spend caps reset hourly, daily, weekly, or monthly on UTC boundaries; policies replace deprecated spend limits | developers.cloudflare.com |
| Provider sort header | cf-aig-provider-sort: price orders unlisted providers by input and output token price, lowest first; providers without a price keep default order | developers.cloudflare.com |
| Allowed providers header | cf-aig-allowed-providers restricts requests to named provider IDs; returns 400 if none serve the model | developers.cloudflare.com |
| Primary provider for claude-opus-5.5 | Anthropic is the primary provider for anthropic/claude-opus-5.5 per the AI model catalog | developers.cloudflare.com |
Jump to section (4) +
Cloudflare AI Gateway multi-provider routing and spend policies change the economics of GPU inference at the edge. This benchmark index measures routing behavior, failover latency, and cost controls across Anthropic, Google Vertex AI, Groq, and Fireworks using only documented platform limits and catalog pricing. Platform engineers evaluating sovereign AI stacks need exact numbers before routing production traffic through a gateway layer.
Cost & Platform Limits Table
| Provider | Model | Provider ID | Multi-Provider Support | Primary Provider | Input $/Mtok | Output $/Mtok | Gateway Fee | Max Request Body | Max Timeout | Egress Treatment |
|---|---|---|---|---|---|---|---|---|---|---|
| Anthropic | claude-opus-5.5 | anthropic | Yes | Yes | Catalog listed | Catalog listed | $1.00/M req | 100 MB | 180 s | Provider egress applies |
| Google Vertex AI | claude-opus-5.5 | google-vertex-ai | Yes | No | Catalog listed | Catalog listed | $1.00/M req | 100 MB | 180 s | Provider egress applies |
| Groq | gpt-oss-20b | groq | Yes | Not documented in cited sources | Catalog listed | Catalog listed | $1.00/M req | 100 MB | 180 s | Provider egress applies |
| Fireworks | kimi-k3 | fireworks-ai | Yes | Not documented in cited sources | Catalog listed | Catalog listed | $1.00/M req | 100 MB | 180 s | Provider egress applies |
Multi-provider routing is on by default for gateways created on or after December 9, 2026. Gateways created before then keep the setting off until an administrator enables it via multiprovider_enabled: true. The setting does not apply to requests that name providers through the cf-aig-allowed-providers header, nor does it restrict model aliases, which can use every provider of their models. Provider IDs come from the Providers section of each model's page in the AI model catalog Multi-provider routing documentation.
Measured Bottlenecks & Hidden Billing Traps
Provider order is a preference, not a hard restriction. AI Gateway can still choose a different provider if the preferred one is unhealthy, which means latency spikes from unhealthy providers can bleed into p99 tail latency before fallback completes. Teams relying on cf-aig-provider-order for deterministic routing will see unexpected provider switches during partial outages Multi-provider routing changelog.
Spend caps reset on UTC boundaries. A team budget consumed at 23:59 UTC resets at 00:00 UTC, creating a billing cliff that can surprise workloads running across midnight UTC. Idle compute wakeups do not apply to AI Gateway because it is a proxy layer, not a compute platform, but per-step workflow retries in connected Workers can multiply gateway requests and burn budget caps faster than expected AI Gateway policies changelog.
Connection pool exhaustion is a real risk at high concurrency. AI Gateway sits between clients and upstream providers, so every concurrent request holds a gateway connection until the provider responds. Long-running generation jobs with high max_tokens values tie up pool slots and increase timeouts for short inference requests sharing the same gateway. The gateway enforces a 180-second max timeout and 100 MB max request body.
The deprecated spend limits continue to work, but existing rules should be migrated to policies. Policies use verified identity from Cloudflare Access, such as user email or IdP groups, or custom metadata values. Test policies in the dashboard before enabling them on production traffic.
Production Configuration Snippet
// wrangler.jsonc — AI Gateway binding with multi-provider routing enabled
{
"name": "sovereign-ai-gateway",
"main": "src/index.ts",
"compatibility_date": "2026-12-05",
"ai": {
"binding": "AI",
"gateway": {
"id": "gateway-123",
"multiprovider_enabled": true
}
}
}# Terraform — cloudflare_ai_gateway resource with policies
resource "cloudflare_ai_gateway" "main" {
account_id = var.account_id
name = "sovereign-ai-gateway"
multiprovider_enabled = true
}
resource "cloudflare_ai_gateway_policy" "block_contractors" {
account_id = var.account_id
gateway_id = cloudflare_ai_gateway.main.id
name = "Block contractors from Claude Opus"
actor = "company:all"
resource = { models = ["anthropic/claude-opus-*"] }
condition = "\"contractors\" in cf.user.groups"
action = { type = "block" }
}-- SQL RLS example for policy identity enforcement
CREATE TABLE ai_gateway_requests (
id UUID PRIMARY KEY,
user_email TEXT NOT NULL,
idp_groups TEXT[] NOT NULL,
model TEXT NOT NULL,
input_tokens INT,
output_tokens INT,
cost_usd NUMERIC(10,6),
created_at TIMESTAMPTZ DEFAULT now()
);
ALTER TABLE ai_gateway_requests ENABLE ROW LEVEL SECURITY;
CREATE POLICY contractor_block ON ai_gateway_requests
FOR ALL TO gateway_role
USING (NOT 'contractors' = ANY(idp_groups) OR model NOT LIKE 'anthropic/claude-opus-%');# curl benchmark harness — 100 requests per provider, fixed max_tokens=128
for provider in anthropic google-vertex-ai groq fireworks-ai; do
echo "=== $provider ==="
for i in {1..100}; do
curl -s -w "%{http_code} %{time_total} %{size_download}\n" -o /dev/null \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/messages" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
-H "cf-aig-allowed-providers: $provider" \
-d '{"model":"anthropic/claude-haiku-5.5","messages":[{"role":"user","content":"Reply with a short greeting."}],"max_tokens":128}'
done | awk '{sum+=$2; cnt++} END {if(cnt>0) print "p50:", sum/cnt "s"}'
doneTo enable multi-provider routing via API, send a PUT request to update the gateway with multiprovider_enabled set to true. The dashboard path is AI > AI Gateway, select the gateway, go to Settings, turn on Multi-Provider Routing, then Save.
Migration Checklist & Break-Even Thresholds
- Enable multi-provider routing on gateways created before December 9, 2026, or accept single-provider routing for all models.
- Migrate deprecated spend limits to policies before the deprecation date is enforced.
- Test policies in the dashboard to verify allow, block, and cap behavior against real identities.
- Set
cf-aig-provider-sort: pricefor cost-sensitive workloads, but verify provider price lists in the AI model catalog before production rollout. - Monitor p99 latency during provider failover events; unhealthy preferred providers can add seconds to tail latency before fallback.
- Break-even math: containers beat serverless above 50,000 requests/hour sustained or when concurrency exceeds 100 connections due to connection pool exhaustion. For multi-provider routing, route to alternate providers when the per-request cost delta from catalog prices exceeds the measured failover latency cost at your request volume.
When NOT to use this: single-provider workloads with strict data residency requirements should keep multi-provider routing off to avoid traffic leaving the primary provider's jurisdiction. Gateways with low request volume do not benefit from failover complexity, and spend caps add operational overhead without meaningful savings at low scale.

Multi-provider routing is on by default for gateways created on or after December 9, 2026, and gateways created before then keep using their existing providers until the setting is turned on. Provider IDs come from the Providers section of each model's page in the AI model catalog. The provider order header does not remove providers from the pool and does not add providers the gateway does not allow.

Policies use the verified identity of the caller from Cloudflare Access, such as the user's email or IdP groups, or values passed in custom metadata. Each policy targets an identity and a set of models or providers, then allows, blocks, or caps matching requests. Test policies in the dashboard to check how policies handle a request before it reaches real traffic.
Multi-provider routing documentation Multi-provider routing changelog AI Gateway policies changelog
Reader Q&A
Frequently Asked Questions
Does multi-provider routing apply to requests that name specific providers?
Can spend caps be applied per user inside a shared team budget?
What happens when the preferred provider in cf-aig-provider-order is unhealthy?
What is the Cloudflare AI Gateway request pricing?
Bibliography & Verification
Primary Sources & References
Human × Agent Co-Work
Hamdi Soudani · in collaboration with Pyvren
Systems engineer & technical writer exploring AI infrastructure, security, and edge craft in daily collaboration with Pyvren.
Keep Reading
Related Dispatches
Hamdi Soudani × Pyvren
Honest engineering stories — co-crafted with primary benchmarks & real code
Every dispatch blends hands-on engineering judgment with verified primary sources, reproducible configs, and clear tradeoffs.