cf-aig-authorization — CF AI Gateway token, authenticates to the gatewaycf-aig-metadata — JSON tags (user/team, ≤5 keys) → written to the logcf-aig-authorization: Bearer <shared token> to all devices uniformly via MDM.$EMAIL, etc.): expand cf-aig-metadata: {"user":"$EMAIL"} into a per-user value at deploy time.managed-settings.json to every device: only the base URL + apiKeyHelper. No static secret on the device.CLAUDE_CODE_API_KEY_HELPER_TTL_MS).cf-aig-identity) → no need to template per-user metadata, and it cannot be spoofed.Once Claude Code points at the gateway's Anthropic endpoint, the following apply automatically:
| TODAY | Unified Billing — a single Cloudflare bill; provider keys are not distributed to devices. |
| TODAY | Full request logging & analytics — tokens, cost and request volume per request. |
| TODAY | Custom metadata, caching, guardrails, rate/token limiting |
| TODAY | Model sourcing options for Claude models — Unified Billing, Bring-Your-Own-Key, Amazon Bedrock, Google Vertex AI. |
Approach AI Gateway provides Dynamic Routing — virtual model endpoints, conditional routing on metadata, and per-route rate/budget limits with automatic fallback. These deliver central model control, metadata/usage-based routing, and client-transparent budget fallback as platform features. Today they are invoked through the OpenAI-compatible schema; because Claude Code speaks the Anthropic Messages schema, it cannot invoke them directly yet. Enabling Claude Code to drive multiple providers requires bidirectional Anthropic↔other-provider translation, which is in development.
| Requirement | Status | Notes |
|---|---|---|
| Multiple providers/models in Claude Code | ROADMAP | Native path in development. Today, Claude Code natively reaches Claude models only. |
| Free switch within an approved set | TODAY ROADMAP | Switching models is available today (client-side). Central enforcement of the approved set is on the roadmap (identity-based model access). |
| Dynamic routing by metadata + usage (virtual endpoint) | ROADMAP | Capability exists in Dynamic Routing; reaching it from Claude Code's Anthropic endpoint is on the roadmap. A third-party protocol-translation proxy, or self-authored code on a Worker, may be needed as an alternative. |
| Auto budget/quota fallback, client-transparent | ROADMAP | Native Dynamic Routing feature (budget-limit node + fallback), already client-transparent — but reachable only via the OpenAI schema today. Native for Claude Code is on the roadmap. A third-party protocol-translation proxy, or self-authored code on a Worker, may be needed as an alternative. |
Approach AI Gateway logs token usage, cost and request volume per request, and supports custom metadata. Tag each request with a user/team identifier, then filter or group by it in logs and analytics.
| Requirement | Status | Notes |
|---|---|---|
| Usage / cost / volume per user or team | TODAY | Achievable today via custom metadata (cf-aig-metadata): tag user/team, then filter and group. |
| Trusted, non-spoofable identity attribution | CLOSED BETA | Verified user/team from SSO is delivered by identity-aware access (in closed beta). Today, client-supplied metadata is used instead. |
Approach With Unified Billing or BYOK, the provider API key lives server-side and is never distributed to devices — the device carries a Cloudflare gateway token, not the provider key. Combined with identity-aware access (Theme E), devices can rely solely on short-lived SSO tokens, with no long-lived secret at all.
| Requirement | Status | Notes |
|---|---|---|
| Provider API key not on device / not hard-coded | TODAY | Achievable today via Unified Billing / BYOK — provider credentials remain server-side. |
| No long-lived secret on the device at all | CLOSED BETA | Delivered via identity-aware access (short-lived SSO tokens) — see Theme E. In closed beta. |
Approach AI Gateway provides gateway-level rate limiting today. Finer-grained per-user/team limits and budget caps are delivered through metadata-key-based controls. An identity-based spend-limit capability is on the roadmap, which will natively enforce limits per identity.
| Requirement | Status | Notes |
|---|---|---|
| Gateway-level rate limiting | TODAY | Available today; applied uniformly across the whole gateway. |
| Per-user/per-team rate & token/budget limits | ROADMAP | Native identity-aware spend limits are in development. Achievable today through metadata-key-based controls. |
apiKeyHelper with a Cloudflare Access token, so that users authenticated through Cloudflare Access obtain a temporary token.Approach
Cloudflare Access sits in front of the gateway. Users authenticate through your IdP (SSO), and the gateway receives a verified
identity on every request. Claude Code integrates via apiKeyHelper running a Cloudflare Access login, which
yields a short-lived Access token per session, with ANTHROPIC_BASE_URL pointed at the Access-protected gateway — no
long-lived key on the device, and identity flows into logs.
| Requirement | Status | Notes |
|---|---|---|
| Per-user dynamically issued short-lived credentials | CLOSED BETA | Yes — this is precisely what identity-aware access provides (SSO login flow). In closed beta. |
Claude Code apiKeyHelper + Cloudflare Access token | CLOSED BETA | Yes — this is the documented Claude Code setup pattern for identity-aware access. In closed beta. |
| Per-user model allowlists & identity-aware spend limits | ROADMAP | The identity front-door (authentication & attribution) is the first phase; per-user policy enforcement is a later phase. |
| Phase | What to do |
|---|---|
| Phase 1 — Today | Run Claude Code on Claude models through the gateway's Anthropic endpoint with Unified Billing. Use custom metadata for per-user/team usage and cost reporting. Add a lightweight proxy where per-user policy, central model control, or budget fallback is needed today. |
| Phase 2 — As capabilities land | Adopt identity-aware access (SSO short-lived tokens, no device secret, trusted attribution), then central identity-based model governance and cost/smart routing — consolidating the Phase 1 proxy responsibilities onto native gateway features. |
The same building blocks extend beyond Claude Code. MCP clients reach LLMs through AI Gateway, and reach internal & SaaS systems through Cloudflare Zero Trust MCP Server Portals gated by Access (ZTNA). The diagram below reflects Cloudflare's own internal / reference deployment.
portal_codemode_search (discover tools via codemode.tools()) and portal_codemode_execute (call them, supports parallel calls).