Claude Code · Facts verified 2026-10-13

Can I use Cloudflare AI Gateway with Claude Code?

Yes, for Claude models. Cloudflare documents an /anthropic endpoint on your gateway that serves the /v1/messages API Claude Code expects, with your gateway token in a cf-aig-authorization header. It can't route Claude Code to other models: the Auto Router and Dynamic Routing don't accept Anthropic-format requests.

terminalgateway.ai.cloudflare.com
# Cloudflare's documented setup, paid from Unified Billing credits
export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/<GATEWAY_ID>/anthropic"
export ANTHROPIC_API_KEY="<CF_AIG_TOKEN>"
export ANTHROPIC_CUSTOM_HEADERS="cf-aig-authorization: Bearer <CF_AIG_TOKEN>"
claude

Shell exports last for one terminal; put the same values in the env block of ~/.claude/settings.json to keep them. Run /status in Claude Code to check the base URL.

What works through the gateway

Claude CodeCodexOpenCode
Documented setupYes, /anthropicYes, /openai on the Responses APIYes, per provider
ModelsClaude on Anthropic, Bedrock or VertexOpenAI models onlyAnthropic, OpenAI, Google and xAI
Unified BillingYesYesYes
Auto Router (cloudflare/auto)No: Messages format isn't acceptedNot in the Codex guideYes, through the /compat endpoint
Dynamic RoutingNo: Messages requests return 400No: Responses format isn't acceptedChat Completions only
Spend limits and logsYesYesYes

From Cloudflare's coding-agent guides for Claude Code, Codex and OpenCode, plus the Auto Router and Dynamic Routing pages, October 13, 2026. We have not run a Claude Code session through a Cloudflare gateway ourselves.

Gotchas

  • If you see auth errors with Unified Billing, set ANTHROPIC_API_KEY to an empty string: Cloudflare's Claude Code page says the value is ignored, its Anthropic provider page that it makes the request fail.
  • Unified Billing allows 200 requests per 60 seconds per gateway. Claude Code with parallel subagents can reach that; your own Anthropic key isn't limited this way.
  • Spend limits are eventually consistent, so a burst of subagent requests can pass the limit before it blocks with 429.
  • Codex doesn't expand environment variables inside base_url: write the account and gateway IDs out in full.
  • Teams can gate the gateway behind Cloudflare Access with an apiKeyHelper that calls cloudflared.

Every way to run other models in Claude Code

What a request costs

Through Unified Billing, Claude costs Anthropic's list price plus 5%: about $74 for a month of typical coding-agent days on Sonnet 5.5, or $148 on Opus 5.5. On your own Anthropic key, drop the 5%.

Cloudflare AI Gateway pricing in full

The catch

Through Cloudflare, Claude Code stays on Claude. Every step of the session, file reads included, runs on the model you configured at that model's price, because the routing features that could move routine steps to a cheaper model don't accept Anthropic's request format.

Where Standard Compute fits

Standard Compute takes the same ANTHROPIC_BASE_URL and does what Cloudflare's routers can't for Messages requests: it moves file reads and other routine steps off Claude, inside a plan from $19 that stops at its budget. Codex works on /v1/responses with Claude, GPT and open models. For Claude Code's logs and DLP inside an existing Cloudflare account on your own Anthropic key, Cloudflare does the job.

FAQ

Does Cloudflare AI Gateway support the Anthropic Messages API?

Yes. Cloudflare's Claude Code guide says its Anthropic endpoint "exposes the same /v1/messages API that Claude Code expects". The base URL is your gateway's address on gateway.ai.cloudflare.com, ending in /anthropic.

Can Claude Code use GPT or open models through Cloudflare AI Gateway?

Cloudflare doesn't document it. Its Claude Code guide covers Anthropic, Bedrock and Vertex, and the Auto Router and Dynamic Routing reject Anthropic-format requests.

Can Codex use Claude through Cloudflare AI Gateway?

No. Cloudflare's Codex guide says only OpenAI models that support the Responses API work; Anthropic or Google models don't work with Codex through that configuration.

Do I need an Anthropic account to use Claude Code through Cloudflare?

No, if you use Unified Billing: Cloudflare holds the credentials and bills your credits. Without it, you pass your own Anthropic key and the gateway forwards it.

Related guides