Cloud · Analysis
Cloudflare AI Gateway Policies: What Breaks on Migration
Cloudflare replaced AI Gateway spend limits with identity-based policies on 4 Dec 2026. The switch turns on deny-by-default, moves budgets to UTC calendar windows and drops model fallback on a 429.
Nalini Groves · Dec 5, 2026 · 10 min read

On this page
Cloudflare deprecated AI Gateway spend limits on 4 December 2026 and replaced them with policies: rules that cap spend per user, team or email domain, and can block or allow specific models, using identity from Cloudflare Access or the cf-aig-metadata header. Existing spend-limit rules keep working, and as of 5 Dec 2026 Cloudflare has not published a date for turning them off.
The docs include a table that maps each old rule to a policy. What the table does not show is how behaviour shifts. The first policy you publish switches the gateway to deny-by-default. Budgets reset on UTC calendar boundaries. A used-up cap returns a hard 429 instead of falling back to a cheaper model, and a gateway that cannot read current spend lets the request through. This piece is a dated map of those changes, a migration order that does not lock out your own services, and a worked three-budget example.
Behaviour described here comes from Cloudflare's 4 December changelog and AI Gateway documentation, all checked on 5 Dec 2026. Metarix did not run a gateway to test it, and dollar amounts in the examples are illustrative.
What Cloudflare shipped on 4 December
A policy has four parts. Who names the caller and, for spend caps, the budget bucket: Everyone, one user by email, an email domain, or a custom actor string such as user:{cf.user.id} that resolves per request. Resources narrows it to models or providers, with * wildcards for model IDs. Action is allow until capped, allow without a cap, or block (including an allowlist form that blocks everything except the listed models). An optional condition in Common Expression Language (CEL) filters on IdP groups, email, country or metadata.
Spend limits could only count money. Policies also decide who may call which model, so the contractor who should never touch Claude Opus now gets a 403 at the gateway instead of a line item at month end. The gateway itself is Cloudflare's AI Gateway; for how it stacks up against Vercel and OpenRouter, see the Metarix AI gateways comparison.
Scroll the table horizontally on smaller screens.
| Item | Spend limits (deprecated) | Policies |
|---|---|---|
| Status | Deprecated 4 Dec 2026; still enforced; no removal date published | Available 4 Dec 2026 in the dashboard and API |
| Rules per gateway | Up to 20 | Up to 100 |
| Identity inputs | Model, provider, custom metadata (including cf.user_id from Access) | Access user ID, email, IdP groups, service-token common name, custom claims, country, custom metadata |
| What a rule can do | Cap spend | Cap spend, allow without a cap, block, or allowlist models |
| Time window | Rolling or fixed, per the spend limits page | Hourly, daily, weekly or monthly, aligned to UTC |
| When the budget runs out | 429; a dynamic route can fall back to another model | 429 for the whole request; no fallback |
| Requests matching no rule | Not limited | Rejected with 403 once any policy exists |
| Change control | Saved per rule | Staged, tested with Test policies, then published in the dashboard; the API applies changes directly; up to 15 minutes to propagate |
Status by surface
- Settings > Spend limits: deprecated on 4 Dec 2026 but still enforced. While both features are configured, a request has to pass your spend-limit rules and your policies.
- Policies in the dashboard: staged changes, a Test policies panel, then Publish. Deleting a policy applies at once, without staging.
- Policies via the API: the
/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/policiesendpoints apply changes directly, with no staging step. Reads need AI Gateway read permission; writes need edit permission. - Budget Limit nodes in dynamic routes: not deprecated. Cloudflare's dynamic routing page now says to use them when a spent budget should fall back to a cheaper model, and to use policies for hard budgets.
What breaks when you switch
Scroll the table horizontally on smaller screens.
| Behaviour | Before (spend limits) | After (policies) | What to check |
|---|---|---|---|
| Unmatched traffic | Rules only limit what they match | First published policy turns on deny-by-default (403) | Stage a catch-all policy before anything restrictive |
| Budget resets | Rolling or fixed window | Calendar windows on UTC: 00:00 daily, Monday weekly, the 1st monthly | Local reset times; spend allowed either side of midnight UTC |
| Budget used up in a dynamic route | Route can fall back to another model | Whole request rejected with 429 | Keep fallback budgets on Budget Limit nodes |
| Two caps, same bucket and window | Each rule enforced on its own | Highest amount applies | Give a tighter cap its own actor string |
| Spend data unavailable | Not documented | Request allowed (fail-open) | Do not treat a cap as a hard security control |
| IdP groups cannot load | Not applicable | Request rejected with 503 | Group-based policies depend on your IdP sync |
| Cached responses | Not documented | Skip spend caps; still subject to block and deny-by-default | Cache hits do not count toward budgets |
Deny-by-default arrives with the first policy
A gateway with no policies allows everything. Publish one block policy, say contractors off Claude Opus, and every request that matches no policy now gets 403 Access denied by policy. That includes health checks, eval jobs and the batch worker nobody remembers. Cloudflare's own migration steps put a catch-all first for this reason: Everyone, all models and providers, either allow without a cap or a company-wide ceiling.
Block also wins over everything. If a block policy references an identity field the request does not carry, the docs say the gateway blocks the request when the resource matches. Other policy types that hit a missing field simply do not apply.
UTC calendar windows
A daily cap resets at 00:00 UTC. That is 02:00 in Cairo, 04:00 in Dubai, 05:00 in Karachi and 19:00 the previous evening in New York while US Eastern is on standard time. Weekly caps turn over at 00:00 UTC on Monday, which is Sunday evening on the US east coast. Monthly caps reset on the 1st.
Calendar windows also allow a burst around the boundary. A user with a $40 daily cap who spends it between 23:00 and 23:59 UTC gets a fresh $40 at midnight, so $80 can go out in about an hour. A rolling 24-hour window would not allow that. If the burst matters, add an hourly cap next to the daily one. Cloudflare's rule that the highest cap wins is stated for caps that share a time window, so an $8 hourly cap and a $40 daily cap on the same actor should both apply, holding the 23:00 to 01:00 UTC spend to $16. Check that with a staged policy before relying on it.
No fallback on a 429
This is the behaviour change most likely to hurt users. With spend limits, a rule on Claude Opus inside a dynamic route could tip the route to a cheaper fallback model once the budget ran out. Policies are evaluated once, before the route runs. A capped request is rejected outright. If your app relied on a quiet downgrade, moving that rule to a policy turns it into an error. Leave those budgets on Budget Limit nodes in the route.
Identity: Access is verified, metadata is not
With the gateway behind Cloudflare Access, policies can read the Access user ID (the JWT sub claim), email, IdP groups, a service token's common name and custom claims. Access needs a custom domain on the gateway first. Without Access, you pass identity in cf-aig-metadata, and Cloudflare is blunt that it cannot verify that header. Metadata-based policies are cost accounting for requests from your own backend. They are not a control against a client that can set its own headers.
Three smaller constraints come with the identity choice:
- Service tokens carry no email and no groups. A CI job on a service token will not match an email-domain policy, so give it an explicit policy and run it through Test policies.
- Group-based rules tie gateway availability to your identity provider. If AI Gateway cannot load a user's groups, it returns 503 rather than guessing.
- The metadata key limit disagrees between pages. The Policies page says the header must be a flat JSON object with up to five keys. The custom metadata page and the 30 November changelog say up to 10 entries and 12,288 bytes, trimmed from the end when over. Until Cloudflare reconciles them, keep the keys your policies read among the first five.
Worked example: three budgets on one request
Take a research engineer behind Access with three policies in force: a company budget of $2,000 a month for Everyone, a research team budget of $600 a month (actor team:research, condition metadata.team == "research"), and a personal cap of $40 a day (actor user:{cf.user.id}). The request has to be under the cap in every bucket that applies.

The company and team buckets have room. The personal bucket shows $40.20 spent, so the request gets a 429 whose body names the bucket and reports spent and limit. The extra 20 cents is not a typo. AI Gateway records a request's cost after it completes, so parallel calls from an agent can push a bucket past its cap before enforcement catches up. Size caps with that slack in mind.
Now suppose finance asks for a tighter $300 monthly cap on contractors in the research team. Written with the same team:research actor and the same monthly window, it lands in the same bucket as the $600 policy, and the highest amount applies. The $300 cap does nothing. Give it its own actor, such as team:research-contractors, so it becomes a separate bucket that is checked alongside the others.
A migration order that does not lock anyone out
- List your spend-limit rules (at most 20 per gateway) and mark any that protect a model inside a dynamic route.
- Stage a catch-all policy first: Everyone, all models and providers, allow without a cap or your company ceiling.
- Recreate each rule from Cloudflare's mapping: a metadata split by value becomes an actor such as
user:{metadata.user_id}, a filter by value becomes a condition, and a model split becomes one policy per model. - Keep route fallbacks on Budget Limit nodes instead of converting them.
- Use Test policies with a normal user, a contractor, a service token and a request with no metadata. Test results ignore spend already recorded, so they show allow or block only.
- Publish, then allow up to 15 minutes before judging the logs.
- Delete the spend-limit rules once policies cover the same traffic. Until then both are enforced.
- Update clients to handle the two errors differently.
That last step matters for agents. A 403 from a policy will not clear on retry; only a policy change fixes it. A spend-cap 429 will not clear until the next UTC window, so a client that retries every 429 with backoff, as most rate-limit handlers do, will just burn retries. Policies also return no remaining-budget headers. The Metarix guide to LLM API rate limits covers retry logic for the per-minute 429s that are worth retrying.
Check your configs for these
- Any caller without identity, such as uptime probes, eval runners or batch jobs, needs a matching policy before you publish.
- Retry handlers that treat every 429 as transient should check the error message for Spending limit exceeded and stop.
- Models without known pricing, such as self-hosted endpoints, do not count toward any budget unless you set a custom cost.
- Model wildcards stop at a slash:
openai/gpt-*matchesopenai/gpt-5.5, and provider names take no wildcards. - Metadata keys starting with
cf.are reserved and stripped, so do not try to fakecf.user_idfrom the client. - Gateways close to 100 policies get a 403 on the next create; per-user caps belong in one actor bucket, not one policy per person.
Cloudflare's pricing page, checked 5 Dec 2026, does not list a separate charge for policies. Cloudflare Access is its own product, so check your Zero Trust plan before putting a large team behind it. Platform context for the other clouds is in the Metarix cloud AI platforms hub and on the Cloudflare company page.
Our take
Migrate gateways that use spend limits as plain hard budgets now, while both systems run side by side and nothing is scheduled for removal. Policies are stricter and more expressive, and the deny-by-default switch is safer to meet on your own schedule than after a removal notice.
Do not convert every rule, though. Budgets that exist to downgrade a model belong on dynamic-route Budget Limit nodes. And if your gateway is not behind Access, treat metadata policies as spend accounting, not access control, because the gateway fails open when it cannot read spend and cannot verify the header.
First step this week: stage an Everyone catch-all, run Test policies against your CI service token and one metadata-less request, and only then publish the first restrictive policy.
Sources
- Cloudflare Changelog: Control spend and model access with AI Gateway policies, 4 Dec 2026
- Cloudflare Docs: AI Gateway Policies, checked 5 Dec 2026
- Cloudflare Docs: AI Gateway Spend limits, checked 5 Dec 2026
- Cloudflare Docs: Dynamic routes, checked 5 Dec 2026
- Cloudflare Docs: AI Gateway with Cloudflare Access, checked 5 Dec 2026
- Cloudflare Docs: Custom metadata, checked 5 Dec 2026
- Cloudflare Changelog: Send up to 10 custom metadata entries per request, 30 Nov 2026
- Cloudflare Docs: AI Gateway pricing and limits, checked 5 Dec 2026
Tools covered in this article
Frequently asked questions
- Do I need Cloudflare Access to use AI Gateway policies?
- No. Without Access you can pass identity in the cf-aig-metadata header and reference it as metadata.<key>. Cloudflare cannot verify that header, so only rely on it for requests that come from your own backend. Access is required for verified user IDs, emails and IdP groups.
- When will AI Gateway spend limits stop working?
- Cloudflare had not published a removal date as of 5 Dec 2026. Spend limits were deprecated on 4 Dec 2026 and existing rules keep working; while both are configured, a request must pass both your spend-limit rules and your policies.
- Can users see how much of their AI Gateway budget is left?
- Not from response headers: policies return no remaining-budget headers. When a cap is hit, the 429 body includes the bucket ID, the amount spent and the limit. Admins can read policies and their usage through the Cloudflare API with AI Gateway read permission.
- Do AI Gateway budgets count BYOK requests?
- The policies page says spend is the cost AI Gateway calculates per request, and models without known pricing do not count. The older spend limits page said limits covered both Unified Billing and BYOK requests for models with known pricing; the policies page does not repeat that line, so check the usage view for your gateway.
Follow Metarix
Digital media intelligence hub
AI SaaS · developer workflows · architecture