Skip to content

Claude Code gateway: per-developer keys, budgets, and logs

A Claude Code gateway is a proxy between developers' sessions and the model provider. The settings that point at it, what it must forward, and what it costs.

Published
Reading time
14 min read

In short

  • A Claude Code gateway is a proxy that every developer's Claude Code session calls instead of the model provider. Two settings point Claude Code at it: ANTHROPIC_BASE_URL and a gateway credential in ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY, or an apiKeyHelper command.
  • The gateway must serve the Anthropic Messages format, stream events as they arrive, and forward the anthropic-beta header, the request body, and upstream errors unchanged. A gateway that strips cache_control returns no error and bills every turn as uncached input.
  • Issue one gateway key per developer. Each person then has a budget, a rate limit, and a row in the log, and offboarding revokes one key.
  • Anthropic does not support routing Claude Code to non-Claude models through any gateway, and prompt caches do not move between providers. Keep each session on one Claude model at one provider.

A Claude Code gateway is a proxy between developers' Claude Code sessions and the model provider. Each session sends its requests to the gateway with a credential the gateway issued. The gateway checks that credential's budget and model access, logs the call, and forwards it to Anthropic, Amazon Bedrock, or Google Cloud with a provider credential the developer never holds.

For a team with dozens of developers, that buys a key and a budget per person, one log of every request, Claude through the cloud account the company already pays, and failover between providers. The price is a service in the path of every request that has to keep pace with each Claude Code release.

What a gateway changes for a Claude Code team

A gateway replaces the credential on each developer's machine with one the gateway issues, which moves authentication, spend tracking, budgets, and audit logging to one place. Anthropic's gateway overview names the two credentials involved: a developer credential that identifies one person to the gateway, and a provider credential that the gateway holds for the whole organization.

Without a gateway, each developer signs in with a claude.ai subscription, an API key, or cloud credentials, and spend is visible per account at best. With one, each developer holds a virtual key, every request carries that identity, and offboarding revokes one key.

CLAUDE CODE SESSIONSPROVIDERSDana's sessionVIRTUAL KEY · DANALee's sessionVIRTUAL KEY · LEECI jobVIRTUAL KEY · CIGatewayANTHROPIC MESSAGES APIIdentify the developerCheck budget and modelSwap in a provider keyRoute, with failoverAnthropic APIAPI KEYAmazon BedrockAWS CREDENTIALSGoogle CloudGCP CREDENTIALSRequest logKEY · MODEL · TOKENS · COST
Each Claude Code session holds its own virtual key. The gateway checks the key, swaps in a provider credential that never reaches the laptop, and writes one log row per request.

Requests sent with a gateway credential are billed per token to the organization's provider account, and the developer's claude.ai subscription is not used. The exception is a session that sets only the base URL and keeps its claude.ai login. Its requests pass through the gateway while the subscription's limits and billing still apply.

The developer still picks the model with /model. The gateway decides where that request goes and whether the key may use it. What an LLM gateway does covers the general pattern.

Which settings point Claude Code at a gateway

Two settings point Claude Code at a gateway: ANTHROPIC_BASE_URL, which sends its API requests to the gateway instead of api.anthropic.com, and one credential setting. Anthropic's connection guide matches the credential setting to the header the gateway reads.

SettingWhat Claude Code does with itUse it when
ANTHROPIC_BASE_URLSends every model request to this addressAlways
ANTHROPIC_AUTH_TOKENSends the value as Authorization: BearerThe gateway reads bearer tokens
ANTHROPIC_API_KEYSends the value as x-api-keyThe gateway reads x-api-key
apiKeyHelperRuns a command and sends its output in both headersThe key rotates or comes from a vault or SSO tool
settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://llm-gateway.example.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-gateway-key"
  }
}

Where the values live decides who can change them. A shell export lasts for one terminal session. The env block of ~/.claude/settings.json applies wherever that user runs Claude Code and overrides a shell export of the same variable. For a fleet, deliver the base URL in a managed settings file through MDM, where a developer's shell cannot override it, and supply the key through apiKeyHelper so each machine fetches its own. From Claude Code v2.1.285, setting allowedProviders to ["customEndpoint"] in the same file refuses every other destination.

What a gateway must support for Claude Code to work

A gateway must serve the Anthropic Messages API format, stream responses as they arrive, and pass headers, body fields, and errors through unchanged. Anthropic's gateway compatibility guide lists what Claude Code sends and which feature breaks when a gateway strips it.

RequirementWhat Claude Code sends or expectsWhat breaks
Messages endpointPOST /v1/messages, with a query string such as ?beta=trueA route matched on the full URL misses the request
StreamingServer-sent events relayed as they arrive, pings includedA buffered response stalls the session
anthropic-beta headerCapability values that change with each releaseAn allowlist of today's values breaks the next release
Tool useTool definitions, plus beta fields such as strict that pair with a beta headerA field forwarded without its header returns 400
Prompt cachingcache_control markers on system blocks and messagesNo error. Every turn bills as uncached input
Token counting/v1/messages/count_tokens, optionalNo error. /context shows an estimate
Error bodiesThe upstream's error text, which Claude Code matches to retryA wrapped error disables that recovery

The prompt caching row is the expensive one. A gateway that drops cache_control, or converts the block-form system prompt to a plain string, returns 200 on every request while each turn pays full input price for the whole history. On the second turn of a test session, cache_read_input_tokens in the response's usage should be well above zero. Prompt caching explains the prefix rule.

The upstream matters as well. With ANTHROPIC_BASE_URL set, Claude Code sends its full set of fields even when the gateway forwards to Bedrock, which accepts a subset. Bridging the difference is the gateway's job. When it cannot, CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 on the client stops most pre-release fields.

One requirement sits outside the API. Claude Code prompts carry source code and XML-style tags that match a web application firewall's cross-site-scripting rules, so a short curl test passes and real sessions get 403. Exempt the /v1/messages path from request-body inspection.

Claude Code with Bedrock or Vertex, direct or through the gateway

Claude Code can call Amazon Bedrock or Google Cloud directly, and a gateway can front either one in two ways. Anthropic's docs now call the Google service Google Cloud's Agent Platform, formerly Vertex AI, and Claude Code's variable names keep the VERTEX spelling.

SetupEach laptop holdsClient settingsChanging provider later
Direct to the cloud providerCloud credentialsCLAUDE_CODE_USE_BEDROCK=1 or CLAUDE_CODE_USE_VERTEX=1, plus region and projectReconfigure every machine
Gateway that exposes the provider's formatA gateway keyANTHROPIC_BEDROCK_BASE_URL, CLAUDE_CODE_USE_BEDROCK=1, and CLAUDE_CODE_SKIP_BEDROCK_AUTH=1Reconfigure every machine
Gateway that exposes the Anthropic formatA gateway keyANTHROPIC_BASE_URL and a credentialEdit the gateway config

Direct access puts cloud credentials on every laptop, and any per-developer budget has to come from the cloud provider's own tooling. The second setup adds keys and logs, and because the client speaks Bedrock's own format, Claude Code sends only the fields Bedrock accepts. The skip-auth variable tells it not to sign requests with AWS credentials, since the gateway holds them.

Aim for the third setup when the gateway can translate. Developer machines stay provider-neutral, so a move from the Anthropic API to Bedrock is a gateway change only.

In every setup, pin model versions. Anthropic's Bedrock page warns that an unpinned alias such as sonnet resolves to Claude Code's built-in default for the provider, which may not be available in your account.

Claude Code Router, LiteLLM, Anthropic's gateway, or Bifrost

The right tool depends on who operates it. Claude Code Router fits one developer, and Anthropic's own gateway fits a team that needs only Claude. A general gateway such as LiteLLM or Bifrost, an open-source AI gateway by Maxim AI, fits when CI jobs, other coding agents, or application traffic share the same keys. Anthropic does not endorse, maintain, or audit third-party gateways, so their compatibility work sits with you and the vendor.

OptionWhat it isIdentity and limitsBest for
Claude apps gatewayAnthropic's self-hosted gateway, run from the claude binarySSO over OIDC, spend caps per user or groupClaude only, through your own cloud account
Claude Code RouterAn MIT-licensed local gateway for coding agentsLocal client keys with request and token limitsOne developer who wants other providers
LiteLLMAn open-source proxy that serves /v1/messagesVirtual keys with budgets, backed by PostgresTeams that already run LiteLLM
BifrostAn Apache 2.0 gateway with an /anthropic endpointVirtual keys, deny by default, with budgets per key and teamOne gateway for coding agents and applications

Claude Code Router is the project many people searching "claude code router" want. As of November 2026 it has about 38,000 GitHub stars. It runs on the developer's own machine, listens on http://127.0.0.1:3456 by default, and gives Claude Code and other agents one local endpoint with provider presets, ordered fallback models, and a request log. Its README says to read the Docker guide before exposing it remotely.

Anthropic's Claude apps gateway needs Claude Code v2.1.195 or later, an OIDC identity provider, PostgreSQL, and a Linux host. It is tested with each Claude Code release, so there is no forwarding list to maintain. Sign-in is a browser SSO step with no service-token flow, so a CI pipeline cannot authenticate through it, and WebSearch is disabled on gateway sessions. Its upstreams are Bedrock, Claude Platform on AWS, Google Cloud, Microsoft Foundry, and the Anthropic API.

LiteLLM connects with the same two variables and a LiteLLM virtual key, and it publishes a Claude Code compatibility matrix that is regenerated daily. LiteLLM alternatives compares it with other gateways.

The walkthrough below uses Bifrost, because its virtual keys deny by default and it keeps a Claude Code session on one provider with no configuration.

How to put Claude Code behind Bifrost

Bifrost accepts Claude Code on its /anthropic path with the same two variables. The setup is to start the gateway, create a virtual key per developer, set the variables, and confirm the request in the log. Everything here is open source unless marked Enterprise.

Start the gateway, then open http://localhost:8080 to add provider credentials:

terminal
npx -y @maximhq/bifrost

A fresh instance has no dashboard password and treats virtual keys as optional. Before sharing it, protect the dashboard, add TLS, and turn on enforce_auth_on_inference so a request without a valid key is rejected.

Next, create one virtual key per developer, in the dashboard or through the API. The name and the budget below are placeholders:

terminal
curl -X POST http://localhost:8080/api/governance/virtual-keys \
  -H "Content-Type: application/json" \
  -d '{
    "name": "claude-code-dana",
    "provider_configs": [
      { "provider": "anthropic", "weight": 1.0, "allowed_models": ["*"], "key_ids": ["*"] }
    ],
    "budgets": [{ "max_limit": 200.00, "reset_duration": "1M" }],
    "is_active": true
  }'

A key with no provider_configs can reach no provider, so a forgotten field fails closed. A team_id places the key under a team with its own budget.

Then verify the key from the developer's machine, using the check in Bifrost's Claude Code guide:

terminal
export ANTHROPIC_BASE_URL=https://bifrost.example.com/anthropic
export ANTHROPIC_AUTH_TOKEN=sk-bf-your-virtual-key
 
curl -sS -w '\n%{http_code}\n' "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "max_tokens": 16, "messages": [{"role": "user", "content": "ping"}]}'

A 200 confirms the URL, the key, and the model. Move the two values into the env block of ~/.claude/settings.json, start claude, and run /status. The Anthropic base URL line should end in /anthropic. Send a prompt, open Logs in the Bifrost dashboard, and confirm the request appears with the expected virtual key, provider, and model.

For Claude on Bedrock, the Bedrock runbook maps a deployment name on the Bedrock provider key to each Bedrock model ID, allows the bedrock provider on the virtual key, and pins Claude Code's tiers to provider-qualified names:

settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://gateway.example.com/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "your-bifrost-virtual-key",
    "ANTHROPIC_MODEL": "bedrock/claude-sonnet-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "bedrock/claude-opus-4-8",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "bedrock/claude-sonnet-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "bedrock/claude-haiku-4-5-20251001"
  }
}

Two gateway behaviors matter here. Session affinity adopts the x-claude-code-session-id header that Claude Code already sends, so a session stays on the provider and key that served it. A virtual key that lists several weighted providers also gets an automatic fallback chain, so the Anthropic API and Bedrock can back each other up when the same model name resolves on both.

Enterprise adds sign-in. After bifrost auth login, the Bifrost CLI hands Claude Code an apiKeyHelper that prints a one-hour session token, so no long-lived secret sits in settings. Bifrost Edge, also Enterprise, routes Claude Code at the machine level with no variables at all, which addresses the endpoint side of shadow AI.

Plan around two limits. As of November 2026, the newest Claude Code version on Bifrost's tested list is 2.1.212, from July 2026, while Anthropic's docs already describe v2.1.314, so test the version you pin. The Bedrock runbook also says to widen the Allowed Headers setting to cover anthropic-beta, while the Claude Code guide says the CLI needs no change there. Check that setting first if a beta feature fails.

The same pattern covers the other coding agents in Bifrost's CLI agents overview, including Codex CLI, Gemini CLI, Cursor, and GitHub Copilot, each with its own caveats. Cursor vs Claude Code covers how the two most common ones differ.

What the gateway log gives you

The gateway log gives you one record per model request with the developer's key, the provider, the model, token counts, cost, and latency.

Claude Code's own headers help. x-claude-code-session-id groups every request of a session, and x-claude-code-agent-id identifies the subagent that issued a request, so parallel agents can be costed separately.

Decide what content to keep before the first developer connects. Claude Code prompts contain source code and command output, and a gateway that logs bodies stores all of it. Bifrost can turn content logging off per virtual key with disable_content_logging. LLM observability lists what to record and what to leave out.

Size rate limits with retries in mind. Claude Code retries transient failures, 429 responses included, up to 10 times with backoff, so a budget error that looks like a rate limit can be retried before the developer sees it. Bifrost answers an exhausted budget with 402 and the type budget_exceeded, and Anthropic's gateway sends 429 with x-should-retry: false. Test what a developer sees when the budget runs out.

What a Claude Code gateway costs

A gateway costs cache efficiency when sessions move, reliability when models are swapped, and a dependency that every developer shares.

Prompt caches do not move. Claude Code's caching docs say the cache lives wherever requests are forwarded and that each model has its own cache. A session that moves to another provider mid-conversation finds no cache there and writes its whole prefix again. On Anthropic's published prices, a five-minute cache write costs 1.25 times the base input price and a cache read costs 0.1 times or less, so that turn's prefix costs at least 12.5 times what a read would have. Keep failover for outages and keep sessions pinned, as LLM routing describes.

Other models work less reliably than Claude. Anthropic does not support routing Claude Code to non-Claude models through any gateway. Claude Code assumes that an unrecognized model ID has the capabilities of a current Claude model, including a 1M token context window. A substitute model must also stream tool-call arguments correctly, and server-side tools such as web search exist only on Claude models. If another model is used at all, the lower-risk place is background work such as session titles, which ANTHROPIC_DEFAULT_HAIKU_MODEL controls. Keep the main session on Claude, because one malformed tool call there breaks a file edit.

The gateway is one more thing in the path. When it is down, every developer stops. Remote Control and voice dictation are unavailable while a gateway credential is active, server-managed settings do not reach gateway sessions, and gateway sessions are not eligible for Anthropic's HIPAA configuration. Version checks and telemetry still go to Anthropic directly unless CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 is set, which also turns off auto-updates. Pin a tested Claude Code version, and retest against the gateway before raising the pin.

Frequently asked questions

What is a Claude Code gateway?

A Claude Code gateway, also called a Claude Code proxy or LLM gateway, is a service that Claude Code calls instead of the model provider. Developers authenticate to it with a credential it issues, and it forwards requests with a provider credential that only the gateway holds. Keys, budgets, and request logs for every developer then live in one place.

How do I set ANTHROPIC_BASE_URL for Claude Code?

Set ANTHROPIC_BASE_URL to the gateway's address, and put the gateway key in ANTHROPIC_AUTH_TOKEN for a bearer-token gateway or ANTHROPIC_API_KEY for an x-api-key gateway. Test with shell exports, then move both to the env block of ~/.claude/settings.json or to managed settings. Run /status and look for the Anthropic base URL line.

Can Claude Code use Amazon Bedrock or Vertex AI through a gateway?

Yes. A gateway that exposes the Anthropic Messages format can forward to Bedrock or Google Cloud while developers set only ANTHROPIC_BASE_URL and a key. A gateway that exposes the provider's own format is reached with ANTHROPIC_BEDROCK_BASE_URL or ANTHROPIC_VERTEX_BASE_URL, plus a skip-auth variable so Claude Code does not sign requests with cloud credentials.

Can Claude Code use other models such as GPT or Gemini?

It can be pointed at them through a gateway that translates the Anthropic Messages format, but Anthropic does not support that setup. Claude Code depends on tool calls for file edits and shell commands, and an upstream that streams tool-call arguments incorrectly fails on them. Keep the main session on a Claude model.

What is Claude Code Router?

Claude Code Router is an MIT-licensed open-source project that runs a local model gateway on a developer's machine, by default at http://127.0.0.1:3456. It gives Claude Code and other coding agents one local endpoint and routes requests to the providers and models the user configures.

Does a Claude subscription still work behind a gateway?

Only if no gateway credential is set. With a gateway key or an apiKeyHelper active, requests are billed per token to the account behind the gateway and the subscription is not used. Setting only ANTHROPIC_BASE_URL keeps the claude.ai login as the credential, so the subscription's limits and billing still apply.

Sources

  1. 01Run Claude Code through a gatewayClaude Code docs
  2. 02Connect Claude Code to an LLM gatewayClaude Code docs
  3. 03Claude Code gateway compatibility guideClaude Code docs
  4. 04Roll out an LLM gateway for your organizationClaude Code docs
  5. 05Claude apps gatewayClaude Code docs
  6. 06Claude Code on Amazon BedrockClaude Code docs
  7. 07How Claude Code uses prompt cachingClaude Code docs
  8. 08Prompt cachingClaude API docs
  9. 09Claude Code RouterGitHub, musistudio/claude-code-router
  10. 10Claude Code (CLI)LiteLLM docs
  11. 11Claude CodeBifrost docs
  12. 12Set up Claude Code with Amazon BedrockBifrost docs