Disclosure: I work on ApiFlux, an AI router with native Anthropic, OpenAI and Gemini endpoints. Everything below applies to any gateway that speaks the Anthropic Messages protocol — the config is not vendor-specific.
If you use Claude Code daily, at some point you'll want to route it through a gateway: for failover when api.anthropic.com returns 529s, for one bill across Claude/GPT/Gemini, or just for a usage log you can actually grep. It should be one environment variable. In practice there are four, and two of them aren't documented anywhere obvious. Here's what broke for us and the config that's been stable for two months.
Why "OpenAI-compatible" is not enough
Most gateways advertise "works with Claude" because they proxy /v1/chat/completions. Claude Code doesn't speak that. It uses the Anthropic Messages API (POST /v1/messages, x-api-key header, anthropic-version header), and the tool-use payload — tool_use / tool_result content blocks, cache_control markers, streaming event types — has no 1:1 mapping onto OpenAI function calling. Translation layers get simple chats right and then quietly drop fields on multi-turn agentic loops. Symptoms: tools that "run" but return empty results, prompt caching silently disabled, or a 400 on the third turn.
Rule of thumb: before pointing Claude Code at a gateway, confirm it exposes a native /v1/messages endpoint. If the docs only mention chat completions, don't.
The four variables
# ~/.zshrc or ~/.bashrc
export ANTHROPIC_BASE_URL="https://apiflux.ai" # your gateway; try ".../v1" if you get path errors
export ANTHROPIC_API_KEY="sk-your-gateway-key" # the GATEWAY key, not your Anthropic key
export DISABLE_INTERLEAVED_THINKING=1
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
The first two are the obvious ones. The last two are the ones that cost us an afternoon.
Claude Code sends anthropic-beta headers by default — interleaved thinking, plus whatever experimental betas the current build enables. Some upstreams behind a gateway (Bedrock and Vertex in particular) don't accept every beta flag, and the failure mode is not a helpful error: you get an empty assistant turn or a generic 400. Setting those two variables strips the beta headers and everything becomes deterministic. You lose interleaved thinking, which for coding tasks we haven't missed.
PowerShell users:
$env:ANTHROPIC_BASE_URL="https://apiflux.ai"
$env:ANTHROPIC_API_KEY="YOUR_GATEWAY_KEY"
$env:DISABLE_INTERLEAVED_THINKING="1"
$env:CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS="1"
Verify with claude doctor, then send one cheap request and check it shows up in the gateway's log with the same API key. If the request succeeds but no log appears, you're on a different key/account than you think.
What failover actually looks like
The reason to bother with all this: a single model ID can sit in front of several upstream channels. On our side claude-opus-5 resolves to Anthropic → Amazon Bedrock → Vertex AI; if the primary returns 529/overloaded the router retries the next channel and Claude Code never sees it. We tried maintaining this ourselves with LiteLLM first; rotating three providers' keys and quotas was more ops than we wanted for a side concern.
Two habits that make gateway debugging painless:
Keep the X-Request-Id response header. It's the same ID in the gateway log — paste it into a support ticket instead of a screenshot.
Use a non-production key while evaluating. Zero-data-retention gateways still log metadata (model, tokens, status); you want that log to be yours to read.
Same key, other CLIs
Once the gateway is set up, the other coding CLIs come free.
Codex CLI (~/.codex/config.toml) — OpenAI protocol, so it's the easy one:
`model_provider = "apiflux"
model = "gpt-5"
[model_providers.apiflux]
name = "ApiFlux"
base_url = "https://apiflux.ai/v1"
env_key = "APIFLUX_API_KEY"`
OpenCode — add a custom OpenAI-compatible provider pointing at https://apiflux.ai/v1 and pick a model ID from the gateway's model list.
Three tools, one key, one invoice.
Cost, since someone will ask
Per 1M tokens, August 2026, gateway price vs. official list:
If you've got Claude Code running through a different gateway, I'd genuinely like to know whether you needed the two beta-disabling variables too, or whether that's specific to Bedrock/Vertex-backed routes. Comments open.
Jason Zhu — building ApiFlux. @ApiFluxAI on X.

Top comments (0)