Cloud Parts

Cloudflare AI Gateway

A proxy between your application and AI model providers such as OpenAI, Anthropic, Google and Workers AI that logs, caches, rate-limits, retries and bills every call in one place.

What it is
API gateways
Type
Commercial product
License
Proprietary
Facts checked
12 October 2026

What it is

Requests to models go through Cloudflare instead of straight to the provider. You either point an existing SDK’s base URL at your gateway’s provider endpoint (gateway.ai.cloudflare.com/v1/{account}/{gateway}/openai), keeping your own provider key or storing it with Cloudflare, or call any model through Cloudflare’s own AI REST API on api.cloudflare.com, which has OpenAI-compatible, OpenAI Responses and Anthropic Messages endpoints and model names like anthropic/claude-sonnet-4. A Worker can use the same env.AI.run() binding it uses for Workers AI. On the way through, the gateway records requests, tokens and cost, and applies whatever you switched on.

Caching serves identical text or image requests from Cloudflare’s cache for up to a month, controlled per request with headers such as cf-aig-cache-ttl. Rate limits (fixed or sliding windows) return 429 once exceeded, spend limits block requests when a dollar budget per user, model or gateway runs out, and dynamic routes branch on request data, split traffic for A/B tests and fall back to another model on errors. The core features, analytics, caching and rate limiting, are free on every plan. With Unified Billing you buy credits from Cloudflare, paying a 5% fee, and use them for third-party providers at their own per-token prices, so one Cloudflare bill replaces several provider accounts.

Why teams pick it

  • A one-line change: swap the base URL, and every request is logged with tokens and cost across all providers
  • Caching, rate limits and spend limits are enforced before a request reaches the provider, which cuts latency and bills for repeated prompts
  • Fallbacks and dynamic routing switch models or providers on errors, by user segment or by percentage, without code changes
  • One API and one bill: Unified Billing covers OpenAI, Anthropic, Google and Workers AI at provider prices plus a 5% fee on credits

Watch out for

  • Caching matches identical requests only; Cloudflare says semantic caching is a plan, not a feature
  • 10 gateways per account on the Free plan and 20 on Paid, and Unified Billing requests are capped at 200 per minute per gateway
  • Another hop and another vendor in the request path, with prompts and responses passing through Cloudflare (logging payloads can be turned off)
  • Logs for gateways created from September 24, 2026 are billed as Workers Logs; older gateways keep stored-log caps (100,000 on Free, 10 million per gateway on Paid)

Alternatives

What all api gateways have in common →

How it fits with other technologies

Call an Anthropic model through a gateway, cached for an hour · bash

curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --header "cf-aig-gateway-id: support-bot" \
  --header "cf-aig-cache-ttl: 3600" \
  --data '{
    "model": "anthropic/claude-sonnet-4",
    "messages": [{ "role": "user", "content": "How do I reset my password?" }]
  }'

# Paid from prepaid AI Gateway credits (Unified Billing): no Anthropic key needed

See it in a real stack

No architecture uses Cloudflare AI Gateway yet. Drop it into the playground and wire it up yourself.Open playground →
Where it came from2023–2026

By 2023 developers building on large language models kept describing the same pain: every API call could be unpredictably expensive, providers changed constantly, and the providers themselves focused on models rather than platform features such as logging and controls. Cloudflare, which already ran a reverse proxy in front of about a fifth of all websites, applied the same idea to AI APIs. Michelle Chen and Yo’av Moshe announced the AI Gateway beta on September 27, 2023, alongside Workers AI and Vectorize.

The first version did what nearly every AI application needs: cache responses, limit and retry requests, and show analytics, for OpenAI, Hugging Face and Replicate, by changing one line of code. A universal endpoint could try one provider and fall back to another. It became generally available in May 2024, having proxied over 500 million requests, with Workers AI and ten other providers supported.

Since then it has become the front door for all AI calls on Cloudflare. Unified Billing let customers pay providers through Cloudflare credits; in May 2026 a REST API on api.cloudflare.com began serving any model through one set of endpoints; spend limits arrived in June; and in August 2026 Workers AI and AI Gateway were merged into one path for model access and billing.

Why it’s built this way

A proxy you opt into by changing the base URL
Keeping the provider’s own request format meant existing SDKs, endpoints and streaming kept working; the only change was the URL, with the provider key passed through.
Cache and rate-limit at the edge
The launch post names cost as a top complaint: serving repeated requests from Cloudflare’s cache and capping traffic keeps bills predictable.
Stay provider-neutral
With new models and providers appearing constantly, Cloudflare pitched one consistent control plane for all of them, “even if they change tomorrow, and then again the day after that.”

Timeline

  1. 2023

    Beta announced on September 27 with caching, rate limiting, analytics and a universal fallback endpoint

  2. 2024

    Generally available in May after proxying over 500 million requests

  3. 2026

    REST API on api.cloudflare.com for any model, May 21

  4. 2026

    Spend limits by user, model or gateway, June 5

  5. 2026

    Workers AI and AI Gateway share one binding, API and bill, August 7

Sources11 · facts checked 12 October 2026

Improve this page on GitHub