# Cloudflare AI Gateway
Cloudflare AI Gateway is [[Cloudflare]]'s managed [[AI Gateway]]. You put it in front of your existing provider calls by changing one URL, and you immediately get analytics, logging, caching, rate limiting and retries without touching the rest of your code.
Do not confuse it with [[Cloudflare Workers AI]]. Workers AI runs open-weight models on Cloudflare's own hardware. AI Gateway runs no models at all; it proxies your requests to [[OpenAI]], [[Anthropic]], Google Gemini, Workers AI, Replicate and a long list of others. Two different products, two different privacy stories, and people mix them up constantly.
Cloudflare made the mix-up easier in 2026. Since May 21, AI Gateway sits behind the AI REST API on api.cloudflare.com (`/ai/run`, plus OpenAI-compatible `/ai/v1/chat/completions` and `/ai/v1/responses` and Anthropic-compatible `/ai/v1/messages`). Since August 7, the Workers AI binding (`env.AI.run()`) reaches third-party models too, and one prepaid credit balance pays for both. Same entry point, same bill. Still two products: one runs models, the other routes, logs and meters them.
## What you get
- **Analytics and logs**: requests, tokens, cost and errors per gateway, with the option to store full request and response bodies
- **Caching**: Cloudflare serves repeated responses from its own cache, which cuts both latency and your provider bill
- **Rate limiting**: throttle by requests over a time window before the traffic ever reaches the provider
- **Dynamic routing**: retries and model fallbacks when a provider misbehaves
- **Unified API**: one endpoint shape across providers, so switching models stays a config change
- **Unified Billing**: buy credits once and call OpenAI, Anthropic, Google or Workers AI without managing provider keys. Provider prices pass through without markup, but Cloudflare adds a 5% fee on credit purchases. Bring-your-own-key still works
- **Spend limits** (June 2026): dollar budgets per model, provider or custom metadata (e.g. $200/day per user), enforced on top of request-based rate limits
- **DLP and Guardrails**: data loss prevention scanning is free; Guardrails runs Llama Guard on Workers AI and bills as Workers AI usage
- **Web Search API** (beta, October 2, 2026): search the web through the gateway with Exa, Linkup or Ceramic.ai, billed at the provider's list price
## Why it matters
If your app already runs on [[Cloudflare Workers]], this is the shortest path from "I have no visibility into my AI spend" to a dashboard that tells you exactly where the money goes. The setup cost is close to zero.
The part worth thinking about: caching and full-body logging both mean Cloudflare holds your prompts. That is the whole point of the product, and it is also a new custodian in your data path. Decide deliberately whether you want log storage on, rather than discovering it later. Since March 2026 there's a middle ground: send `cf-aig-collect-log-payload: false` and the gateway keeps the metadata (tokens, model, cost, status, duration) without the prompt and response bodies.
Pricing: the core features (analytics, caching, rate limiting) are free on every plan. Logs depend on when you started. Accounts whose first gateway dates from September 24, 2026 or later pay Workers Logs pricing; older accounts keep Legacy Logs (100,000 logs total on Workers Free, 10 million per gateway on Workers Paid).
## References
- Documentation: https://developers.cloudflare.com/ai-gateway/
- Supported providers: https://developers.cloudflare.com/ai-gateway/usage/providers/
- Caching configuration: https://developers.cloudflare.com/ai-gateway/configuration/caching/
- Pricing: https://developers.cloudflare.com/ai-gateway/reference/pricing/
- Changelog: https://developers.cloudflare.com/ai-gateway/changelog/
- Changelog, request metadata without payloads (2026-03-17): https://developers.cloudflare.com/changelog/post/2026-03-17-collect-log-payload-header/
- Changelog, AI REST API (2026-05-21): https://developers.cloudflare.com/changelog/post/2026-05-21-rest-api/
- Changelog, spend limits (2026-06-05): https://developers.cloudflare.com/changelog/post/2026-06-05-spend-limits/
- Changelog, Workers AI and AI Gateway unify model access and billing (2026-08-07): https://developers.cloudflare.com/changelog/post/2026-08-07-workers-ai-unified-billing/
- Changelog, Web Search API (2026-10-02): https://developers.cloudflare.com/changelog/post/2026-10-02-introducing-web-search-api/
## Related
- [[AI Gateway]]
- [[Cloudflare]]
- [[Cloudflare Workers]]
- [[Cloudflare Workers AI]]
- [[Cloudflare AI Search]]
- [[Cloudflare Clef]]
- [[Cloudflare Agents SDK]]
- [[Model routing]]
- [[AI Observability]]
- [[Vercel AI Gateway]]
- [[OpenAI]]
- [[Anthropic]]