Skip to main content

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

CLOUD & GPU Benchmark Study
Multi-provider routing · Cloudflare AI Gateway docs
Multi-provider routing · Cloudflare AI Gateway docs Source: developers.cloudflare.com
Field Note · The Short Version 4 min read

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

ProviderModelProvider IDMulti-Provider SupportPrimary ProviderInput $/MtokOutput $/MtokGateway FeeMax Request BodyMax TimeoutEgress Treatment
Anthropicclaude-opus-5.5anthropicYesYesCatalog listedCatalog listed$1.00/M req100 MB180 sProvider egress applies
Google Vertex AIclaude-opus-5.5google-vertex-aiYesNoCatalog listedCatalog listed$1.00/M req100 MB180 sProvider egress applies
Groqgpt-oss-20bgroqYesNot documented in cited sourcesCatalog listedCatalog listed$1.00/M req100 MB180 sProvider egress applies
Fireworkskimi-k3fireworks-aiYesNot documented in cited sourcesCatalog listedCatalog listed$1.00/M req100 MB180 sProvider 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

JSONC13 lines
// 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
    }
  }
}
Terraform16 lines
# 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" }
}
SQL17 lines
-- 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-%');
Bash12 lines
# 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"}'
done

To 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: price for 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 sends requests to any provider serving the model, with automatic failover when the preferred provider is unhealthy.
Multi-provider routing sends requests to any provider serving the model, with automatic failover when the preferred provider is unhealthy.

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.

Control spend and model access with AI Gateway policies · Changelog
Control spend and model access with AI Gateway policies · Changelog

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?
No. Requests that set the cf-aig-allowed-providers header can use the providers they name whether the setting is on or off, bypassing the gateway-level default.
Can spend caps be applied per user inside a shared team budget?
Yes. Policies can give a team or email domain a shared monthly budget and cap spend for each individual user within that shared budget.
What happens when the preferred provider in cf-aig-provider-order is unhealthy?
AI Gateway can still choose a different provider from the pool; provider order is a preference, not a hard restriction, and does not remove providers from the pool.
What is the Cloudflare AI Gateway request pricing?
Cloudflare AI Gateway charges $1.00 per million requests after the free tier; provider token pricing (input/output $/Mtok) is set by each upstream provider and listed in the AI model catalog.

Bibliography & Verification

Primary Sources & References

3 cited sources
  1. [01] developers.cloudflare.com features / routing / multi-provider-routing
  2. [02] developers.cloudflare.com changelog / post / 2026-12-02-multi-provider-routing
  3. [03] developers.cloudflare.com changelog / post / 2026-12-04-policies

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.

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.