Skip to content
News

AI insights

Cloudflare AI Gateway Policies: Per-User Budgets & Access

Cloudflare launched AI Gateway Policies on Dec 4, 2026, adding Access JWT and CEL-based model blocks (403), layered spend caps (429), and Spend limits migration.

#Cloudflare#AI Gateway#Access#비용관리#LLM인프라

Cloudflare AI Gateway Policies: Per-User Budgets & Access

Q. Can you control both model access and monthly spend limits per user or team in Cloudflare AI Gateway? Yes. With AI Gateway Policies announced by Cloudflare on December 4, 2026, you can combine verified Cloudflare Access identities (email and IdP groups) or request metadata with model-level allow/block rules (403) and hourly, daily, weekly, or monthly spend caps (429).

⚠️ Accuracy guardrail: This article only covers facts directly verified from the official Cloudflare Changelog (published December 4, 2026) and the Cloudflare AI Gateway Policies documentation as of December 5, 2026 (KST). The final sunset date for legacy Spend limits, per-model token pricing tables in the Model Catalog, and exact regional propagation times under the 15-minute maximum window were not specified in the documentation and remain unverified.

30-second summary

  • What changed: Announced December 4, 2026, AI Gateway Policies replace legacy Spend limits (now deprecated) and add model/provider access controls (403 block and allowlists) alongside spend caps.
  • Identity-aware rules: Match requests using Cloudflare Access JWT claims (cf.user.id, cf.user.email, cf.user.groups), country (cf.country), or cf-aig-metadata headers (metadata.<key>) from a trusted backend with CEL conditions.
  • Layered budget buckets: A single request can be checked against company, team, and per-user budgets at the same time; exhausting any applicable bucket returns 429.
  • First-policy caveat: Gateways with zero policies allow all traffic, but publishing your very first policy enables deny-by-default (403), so create a baseline allow or cap policy first.

Cloudflare AI Gateway Policies dashboard tab

1. What changed compared to legacy Spend limits

Policies upgrade legacy Spend limits by adding verified user identities and explicit model access controls. Previously, Spend limits focused on metadata-based cost caps and lacked built-in rules to block specific identity groups from expensive models.

Following the December 4 release, Spend limits is deprecated. Existing rules continue to run, and while both features are configured on a gateway, every request must pass both your legacy spend limits and your new policies.

Comparison Legacy Spend limits (Deprecated) New AI Gateway Policies
Identity source Request metadata Cloudflare Access JWT (email, IdP groups) + metadata
Model access control Spend-cap enforcement block, allowlist (block + except: true), no-limit, limit
Budget reset Rule configuration based UTC calendar boundaries (hourly, daily, weekly, monthly)
Dynamic route fallback Could fall back to another model Evaluated before dynamic routes; rejects the whole request
Pre-publish testing Limited simulation Built-in Test policies panel including staged changes

Cloudflare December 4, 2026 AI Gateway Policies changelog announcement

Advertisement

2. Four policy components and the 6-step evaluation order

AI Gateway evaluates every policy on a gateway for every request, regardless of the order you created them. Each policy defines Who (actor), Resources, Action, and optional Conditions (CEL expressions).

  • Who (actor): Choose Everyone, a specific User, an Email domain ending in (such as @example.com), or a dynamic Actor bucket like team:engineering, user:{cf.user.id}, or user:{metadata.user_id}.
  • Resources: Target all models and providers, specific providers (anthropic), or model IDs with * wildcards (openai/gpt-*; wildcards do not cross /).
  • Action: Select Allow until capped (limit in USD on UTC hourly/daily/weekly/monthly windows), Allow without a cap (no-limit), or Block (403, or except: true for allowlists).
  • Conditions: Add optional boolean CEL expressions such as "contractors" in cf.user.groups or cf.country == "US".

Cloudflare AI Gateway Policies 6-step evaluation flow

On each incoming request, AI Gateway runs six steps:

  1. Match: Find all policies whose resources match the request and whose CEL condition evaluates to true.
  2. Block wins: If any matching policy is a block, reject immediately with 403. No allow policy can override a block.
  3. Group by budget: Group remaining matching policies by their resolved actor and resource into budget buckets.
  4. Resolve each bucket: An Allow without a cap policy skips spend checks for that bucket; multiple caps with the same window resolve to the highest amount.
  5. Check every bucket: Every applicable bucket (company, team, and personal) must be under its limit, or AI Gateway returns 429 (Spending limit exceeded).
  6. Deny by default: If zero policies match, reject with 403 (Access denied by policy).

Q. How do you block contractors from Claude Opus while restricting interns to two lightweight models? Add a block policy targeting anthropic/claude-opus-* when "contractors" in cf.user.groups, and for interns combine a block policy with "except": true on the allowed models plus a limit or no-limit policy covering those models.

{
  "name": "Block contractors from Claude Opus",
  "actor": "company:all",
  "resource": { "models": ["anthropic/claude-opus-*"] },
  "condition": "\"contractors\" in cf.user.groups",
  "action": { "type": "block" }
}

3. Cloudflare Access vs. custom metadata, and the API

Use Cloudflare Access for client-facing gateways, and reserve cf-aig-metadata for requests sent from a trusted backend. The cf-aig-metadata header must be a flat JSON object with up to five keys; nested objects or arrays cause AI Gateway to ignore the header.

In the dashboard Policies tab, you can stage multiple edits with Stage policy, verify them with Test policies (without calling providers or recording spend), and deploy them together via Publish changes. Via the REST API (.../ai-gateway/gateways/{gateway_id}/policies), changes apply directly without staging, and /policies/{policy_id}/usage breaks down spend and request counts per actor over up to 90 days.

If you are already pairing multi-provider routing and price sorting or self-hosted workerd clustering, Policies let you enforce user- and model-level cost guardrails right at the gateway layer.

4. Five operational limits to check before rolling out

Review default-deny behavior, dynamic routes, and propagation timing before enabling policies in production.

  1. Deny-by-default turns on with the first policy: Publishing a single restrictive policy without a baseline allow policy blocks all other traffic with 403. Always publish a baseline rule (such as Everyone on All models and providers) first.
  2. No dynamic route fallbacks: Policies run once per request before dynamic routes execute, so blocked or capped requests fail outright instead of falling back to another model.
  3. Up to 15-minute propagation: Creating, editing, or toggling policies can take up to 15 minutes to propagate globally, whereas deleting a policy takes effect immediately.
  4. Cached responses and estimated spend: Cached hits still enforce block rules (403) but skip spend caps (429). Costs are recorded post-response, so concurrent bursts can slightly exceed a cap.
  5. Fail-open behavior with one IdP exception: Policy evaluation or spend-read failures allow traffic through, except when AI Gateway fails to load IdP groups (which returns 503). Each gateway supports up to 100 policies.

Toris's take

  • Teams running internal AI portals or agent gateways: Pair Cloudflare Access with Policies right away to enforce per-department monthly budgets and block expensive model families (claude-opus-*) for external groups.
  • Solo developers and SaaS backends: Even without Cloudflare Access, passing user_id from a trusted backend in cf-aig-metadata with a user:{metadata.user_id} bucket prevents runaway LLM bills per user tier without application-side rate-limit code.
  • Existing Spend limits users: Do not delete legacy rules first—publish a baseline Everyone policy, recreate each rule using the migration mapping, validate with Test policies, and then remove the old rules.

Sources

Advertisement