Cloudflare AI Gateway sits in front of provider APIs and adds caching, rate limiting, retries and fallbacks, request logging, cost analytics, guardrails, and data loss prevention. The core features are free on all plans; Workers Free accounts store 100,000 logs total across all gateways, Workers Paid stores 10,000,000 logs per gateway. Guardrails bill as Workers AI inference. Unified Billing, which lets Cloudflare pay OpenAI, Anthropic, Google AI Studio, Vertex AI, xAI, and Groq on your behalf, applies a 5% fee to purchased credits with no markup on provider rates. The OpenAI-compatible endpoint is the current recommended integration; the older Universal Endpoint is deprecated.
- The proxy is free on all plans: dashboard analytics, caching, and rate limiting cost nothing.
- Log storage is the real cap: 100,000 logs total on Workers Free, 10,000,000 per gateway on Workers Paid.
- It is a proxy, not an aggregator. You bring your own provider keys, unless you enable Unified Billing.
- Unified Billing covers six providers and charges a 5% fee on credits purchased, no markup on provider rates.
- DLP scanning is free on all plans. Guardrails bill as Workers AI token inference.
- The Universal Endpoint is deprecated. Use
/compat/chat/completionsfor new work.
What it is, precisely
Cloudflare AI Gateway is an observability and control layer for AI traffic. You change your base URL, your requests route through Cloudflare on the way to the provider, and Cloudflare records what happened and applies whatever policies you configured.
The distinction that matters when you are comparing gateways: by default there is no Cloudflare wallet in the loop. Your OpenAI key still bills your OpenAI account. Cloudflare sees the request, caches it, counts it, and forwards it. That is a different product shape from OpenRouter or Vercel AI Gateway, where the vendor holds the provider relationship and you buy credits from them.
| Group | Features |
|---|---|
| Performance and cost | Caching, Spend Limits, Rate Limiting, Dynamic Routing, Custom Costs |
| Security and safety | Guardrails, Data Loss Prevention, Authentication, Bring Your Own Keys |
| Observability | Analytics, Logging, Custom Metadata |
| Reliability | Request retry and model fallbacks |
Cloudflare states these work across 20+ supported AI providers, including Workers AI, OpenAI, Anthropic, Google Gemini, and Replicate.
The two ways to call it
There are three integration shapes in the docs and one of them is on the way out. Pick the OpenAI-compatible endpoint unless you have a reason not to.
OpenAI-compatible endpoint (recommended)
curl -X POST \
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
-H 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
-H 'Content-Type: application/json' \
-d '{
"model": "openai/gpt-5.2",
"messages": [{"role": "user", "content": "What is Cloudflare?"}]
}'
const client = new OpenAI({
apiKey: "{cf_api_token}",
baseURL: "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat",
});
const response = await client.chat.completions.create({
model: "anthropic/claude-4-5-sonnet",
messages: [{ role: "user", content: "Hello, world!" }],
});
Provider-native passthrough
Append the provider slug to your gateway URL and send the provider's own request body unchanged. This is the route when you need a provider feature the OpenAI schema cannot express.
Universal Endpoint (deprecated)
The Universal Endpoint took an array of provider objects and walked down it on failure, reporting which entry succeeded in the cf-aig-step response header. It still works and the documentation still describes it, but Cloudflare now recommends the OpenAI-compatible endpoint for new integrations. Do not build new fallback chains on it.
Setting one up
Create a gateway
In the Cloudflare dashboard, AI, AI Gateway, Create Gateway. Name it. You get an account ID and a gateway ID, and both go in the URL. The default gateway ID is default.
Decide who holds the provider key
Either send the provider key on each request as you would normally, or store it in Cloudflare under BYOK so requests carry only your gateway token. The precedence order is: a provider key on the request wins, then a stored BYOK key under the default alias, then Unified Billing.
Point your client at the gateway
export OPENAI_BASE_URL="https://gateway.ai.cloudflare.com/v1/$CF_ACCOUNT_ID/$CF_GATEWAY_ID/compat"
Turn on caching before you turn on anything else
Caching is the feature with the clearest payback and no downside for idempotent traffic. It serves repeat requests from Cloudflare instead of the provider, which cuts both latency and token spend.
Check the logs are landing, then set a retention policy
Logs are the thing you will hit a limit on first. See the pricing section.
What it costs
| Item | Cost |
|---|---|
| Dashboard analytics, caching, rate limiting | Free on all plans |
| Log storage, Workers Free | 100,000 logs total across all gateways |
| Log storage, Workers Paid | 10,000,000 logs per gateway |
| Data Loss Prevention scanning | Free on all plans (two predefined profiles on basic accounts) |
| Guardrails | Billed as Workers AI token-based inference |
| Unified Billing | 5% fee on all credits purchased; no markup on provider rates |
| Logpush | Workers Paid only. 10 million per month, then +$0.05 per million |
Unified Billing, and when it is worth 5%
Unified Billing is Cloudflare's answer to "I do not want six provider accounts". You buy credits, Cloudflare pays OpenAI, Anthropic, Google AI Studio, Google Vertex AI, xAI, and Groq on your behalf, and you get one bill. Provider inference passes through at their rates; the 5% applies to the credit purchase.
It does not replace BYOK. The credential precedence stays: request-level key first, stored BYOK key second, Unified Billing last. So you can run most traffic on your own OpenAI contract and let Unified Billing catch the two providers you have not opened accounts with.
The honest limits
- It is a proxy, not a catalogue. Outside Unified Billing's six providers, you still open and manage every provider account yourself. If the reason you want a gateway is "one key for everything", this is only two-thirds of that.
- The Workers Free log cap is tight. 100,000 logs across all gateways, total, not per month per gateway. A moderately busy agent fleet burns that in days, and logs are the whole point of putting a gateway in the path.
- Guardrails are metered inference. Evaluating long prompts with a Workers AI model is not free, and the cost scales with exactly the traffic you most want to inspect.
- Unified Billing is six providers. Not twenty. Check yours is on the list before planning a migration around it.
- The Universal Endpoint is deprecated while remaining the shape most third-party tutorials teach.
- The account and gateway IDs are in the URL. That is fine, but it means rotating a gateway is a config change everywhere, not a key rotation.
Questions people ask
What is Cloudflare AI Gateway?
It is a proxy you put between your application and AI providers. It adds caching, rate limiting, request retries and model fallbacks, logging, and cost analytics across 20+ providers including Workers AI, OpenAI, Anthropic, Google Gemini, and Replicate. By default you keep your own provider keys and your own provider bills; Cloudflare only sits in the path.
Is Cloudflare AI Gateway free?
The core is. Dashboard analytics, caching, and rate limiting are free on all plans, and DLP scanning is free on all plans. The limits are on log storage: 100,000 logs total across all gateways on Workers Free, and 10,000,000 logs per gateway on Workers Paid. Guardrails bill as Workers AI inference, and Logpush requires Workers Paid.
Does Cloudflare AI Gateway mark up model costs?
No. Provider rates pass through with no markup. The only percentage in the product is Unified Billing, where a 5% fee applies to the credits you purchase, not to the inference itself. Outside Unified Billing you pay the provider directly with your own key and Cloudflare takes nothing.
What is Cloudflare AI Gateway Unified Billing?
It lets you call Workers AI plus OpenAI, Anthropic, Google AI Studio, Google Vertex AI, xAI, and Groq on Cloudflare credits and receive a single Cloudflare bill. Credits deduct in real time and can auto top-up. A 5% fee applies to credits purchased. It does not replace BYOK: a key on the request wins, then a stored BYOK key, then Unified Billing.
What is the Cloudflare AI Gateway endpoint URL?
The OpenAI-compatible endpoint is https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions, with models named as provider/model, for example openai/gpt-5.2. The older Universal Endpoint at https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id} still functions but is deprecated for new integrations.
Cloudflare AI Gateway or OpenRouter?
Different jobs. OpenRouter is an aggregator: one key, one wallet, the widest catalogue, and a 5.5% fee when you load credits. Cloudflare is a control plane over provider accounts you already hold, so your enterprise agreements, discounts, and data terms with each provider survive. Choose Cloudflare when the provider relationships are the asset, OpenRouter when you want to stop managing them.
Sources
Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.
- Cloudflare AI Gateway documentation feature overview and provider list
- Cloudflare AI Gateway pricing log caps, DLP, guardrails, Logpush
- Cloudflare AI Gateway Unified Billing 5% fee, six providers, credential precedence
- Cloudflare AI Gateway OpenAI-compatible endpoint URL format and model naming
- Cloudflare AI Gateway features index the current feature set