Blog · · By Dhrumil Barot, Founder
6 Best Claude Code Gateways: Env Vars and Fees Compared
Six gateways work with Claude Code: Claude apps gateway, LiteLLM, OpenRouter, Vercel, Cloudflare and Portkey. Exact env vars, fees on $1,000 of spend and what each logs, checked 2026-11-12.
TL;DR: Six gateways work with Claude Code today: Claude apps gateway (Anthropic's own), LiteLLM, OpenRouter, Vercel AI Gateway, Cloudflare AI Gateway and Portkey. On $1,000 a month of Claude Code spend the gateway fee runs from $0 (self-hosted, Vercel, BYOK on Cloudflare or OpenRouter) to $55 (OpenRouter credits on the Standard plan), prices checked 2026-11-12. Pick by who must sign in and where logs may go, not by fee: the fee gap is $55 at most.
A Claude Code gateway is any proxy that serves the Anthropic Messages API at /v1/messages, so Claude Code can send requests to it instead of to Anthropic. You point Claude Code at one with two environment variables, ANTHROPIC_BASE_URL (the gateway address) and ANTHROPIC_AUTH_TOKEN (the gateway credential), per Anthropic's gateway connection guide. The gateway then authenticates the developer, applies budgets and logging, and forwards the call with a key your organization holds. Anthropic ships its own self-hosted option, Claude apps gateway, inside the claude binary; LiteLLM is the open-source self-hosted alternative; OpenRouter, Vercel, Cloudflare and Portkey are hosted. One limit applies to all of them: Anthropic "doesn't support routing Claude Code to non-Claude models through any gateway" (Anthropic docs).

How we judged the gateways
We compared each gateway on five things a team rolling out Claude Code actually has to decide:
- Setup: the exact variables, and whether it needs a custom header or a local server.
- Format: does it serve the Anthropic Messages format natively, and does it forward the
anthropic-betaandanthropic-versionheaders Claude Code depends on? The gateway protocol reference lists/v1/messagesas required and/v1/messages/count_tokensas optional. - Fees: what the gateway adds on top of token prices, worked on $1,000 a month.
- Logs: where request logs go and how long they are kept.
- Sign-in: static key, SSO, or a Claude subscription passed through.
We only listed gateways with first-party Claude Code setup docs. Every env var below comes from the vendor's own page, read on 2026-11-12.
Summary table: setup, fees and logs
| Gateway | Hosting | ANTHROPIC_BASE_URL | Fee on tokens | Logs | Sign-in |
|---|---|---|---|---|---|
| Claude apps gateway | Self-hosted, Linux + Postgres | Set by /login to your private host | $0 (you pay hosting) | OTLP to your own stack | Corporate SSO (OIDC) |
| LiteLLM | Self-hosted (open source) | http://localhost:4000 or your host | $0 (you pay hosting) | Your own database | Virtual keys, IdP JWT |
| OpenRouter | Hosted | https://openrouter.ai/api | 5.5% on credit purchases; BYOK free to $25,000/month | OpenRouter activity dashboard | API key |
| Vercel AI Gateway | Hosted | https://ai-gateway.vercel.sh/claude-code | $0 markup | Vercel dashboard and Observability | API key or Claude Max |
| Cloudflare AI Gateway | Hosted | https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/<GATEWAY_ID>/anthropic | $0 with your key; 5% on Unified Billing credits | Workers Logs or Legacy Logs | Gateway token header |
| Portkey | Hosted (or self-hosted gateway) | https://api.portkey.ai | $0 on tokens; plans from $0 to $49/month | 3-day (free) or 30-day retention | API key, Max plan headers |
Sources: each vendor's Claude Code page and pricing page, linked in the sections below, checked 2026-11-12.
1. Claude apps gateway (Anthropic)
Claude apps gateway is Anthropic's self-hosted gateway, built into the same claude binary that runs Claude Code. You start the server with claude gateway --config gateway.yaml, and developers connect through /login with your corporate identity provider (Anthropic docs).
Best for: organizations that want SSO, per-group model allowlists and data residency on Amazon Bedrock, Google Cloud, Microsoft Foundry or Claude Platform on AWS.
What you need: Claude Code v2.1.195 or later on the server and every developer machine, an OIDC identity provider (Okta, Entra ID, Google Workspace, Keycloak, Dex; SAML and LDAP aren't supported), PostgreSQL 11 or later, and a Linux host. The gateway's hostname must resolve to private IP addresses only; Claude Code rejects a public one at sign-in, because a trusted gateway can push settings to developer machines.
Pricing: no gateway fee. You pay your upstream provider at API rates plus your own hosting and Postgres.
What it logs: OTLP usage metrics to your observability stack. Its data plane sends nothing to Anthropic unless the Anthropic API is a configured upstream (gateway overview).
Limits: sign-in is a browser SSO step with no service-token flow, so CI pipelines must call the provider directly. Its advantage is version lockstep: it ships with each Claude Code release, so new anthropic-beta values are forwarded without anyone maintaining an allowlist.
2. LiteLLM
LiteLLM is an open-source, self-hosted proxy that serves the Anthropic Messages format at /v1/messages in front of any model in its config (LiteLLM Claude Code docs).
export ANTHROPIC_BASE_URL="http://localhost:4000"
export ANTHROPIC_AUTH_TOKEN="$LITELLM_API_KEY" # a LiteLLM virtual key
export ANTHROPIC_MODEL="claude-sonnet-5" # must match a model_name in config.yaml
claudeBest for: platform teams that already run LiteLLM for other apps and want per-key budgets and spend logs in their own database.
Pricing: the open-source proxy has no license fee; enterprise features are a paid tier. Your real cost is the server, Postgres and upgrades. We priced that in LiteLLM vs OpenRouter vs managed gateways.
Gotcha you will hit: the /model picker still lists Anthropic's own IDs. Picking one that isn't a model_name in your config fails with Invalid model name passed in. Either add those exact names to model_list or switch models with ANTHROPIC_MODEL.
Limits: you own compatibility. When Claude Code adds a feature behind a new beta header, your proxy must forward it, and Anthropic's docs warn that a gateway which strips it "breaks the corresponding features."
3. OpenRouter
OpenRouter exposes an Anthropic-compatible endpoint, so Claude Code talks to it with no local proxy (OpenRouter Claude Code guide).
export OPENROUTER_API_KEY="sk-or-..."
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY="" # must be explicitly emptyBest for: individuals and small teams who want failover across Anthropic providers, team budgets and one bill without running anything.
Pricing: OpenRouter passes through provider token prices with no markup and charges 5.5% when you buy credits ($0.80 minimum) on the Standard plan, 8% on Business. With your own Anthropic key (BYOK), the first $25,000 of list-price inference a month carries no fee and 5% applies after that (OpenRouter pricing).
Limits: OpenRouter says Claude Code is "only guaranteed to work with the Anthropic first-party provider" and recommends pinning Anthropic as top provider. Treat its multi-provider failover as best effort for Claude Code.
4. Vercel AI Gateway
Vercel runs a dedicated Claude Code compatibility endpoint and a one-line setup command (Vercel docs):
npx vercel@latest ai-gateway setup --agent claude-codeThat writes ~/.claude/settings.json with ANTHROPIC_BASE_URL=https://ai-gateway.vercel.sh/claude-code, empties ANTHROPIC_API_KEY, turns on gateway model discovery, and on macOS stores the key in the Keychain instead of a plaintext file.
Best for: teams already on Vercel, and Claude Max subscribers who want gateway observability without moving to API billing. The Max flow uses ANTHROPIC_CUSTOM_HEADERS="x-ai-gateway-api-key: Bearer <key>" and keeps the plan's usage limits.
Pricing: no markup and no platform fee on tokens; the free tier includes $5 of credit a month on a subset of models, and BYOK requires purchased credits. Payment processing fees can apply, and optional add-ons such as team-wide region pinning are charged separately (Vercel pricing).
Limits: the setup command does not configure the Claude Desktop app; you switch that by hand.
5. Cloudflare AI Gateway
Cloudflare AI Gateway puts caching, rate limiting and logs in front of Anthropic, Amazon Bedrock or Google Vertex AI (Cloudflare docs):
export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/<GATEWAY_ID>/anthropic"
export ANTHROPIC_API_KEY="<CF_AIG_TOKEN>" # required to be set; ignored when the gateway holds the key
export ANTHROPIC_CUSTOM_HEADERS="cf-aig-authorization: Bearer <CF_AIG_TOKEN>"Best for: teams already on Cloudflare that want a free control layer and, optionally, Cloudflare Access sign-in through apiKeyHelper and cloudflared.
Pricing: analytics, caching and rate limiting are free. Unified Billing (Cloudflare pays Anthropic for you) adds 5% to credit purchases, so $100 of credit costs $105; with your own key there is no markup (Cloudflare pricing).
What it logs: accounts that created their first gateway on or after 2026-09-24 use Workers Logs pricing; older accounts keep Legacy Logs, capped at 100,000 logs total on Workers Free and 10,000,000 per gateway on Workers Paid.
Limits: authentication rides in a custom header, so the gateway token sits in ANTHROPIC_CUSTOM_HEADERS rather than a standard credential variable.
6. Portkey
Portkey routes Claude Code through one ANTHROPIC_BASE_URL for every provider and adds traces, budgets and fallbacks (Portkey docs):
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.portkey.ai",
"ANTHROPIC_AUTH_TOKEN": "YOUR_PORTKEY_API_KEY",
"ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: @anthropic-prod"
}
}Best for: teams that want per-session traces (x-portkey-trace-id) and config-driven fallbacks to Bedrock or Vertex.
Pricing: the free tier records 10,000 logs a month with 3-day log retention; the $49 a month plan records 100,000 with 30-day retention and $9 per extra 100,000 requests. Requests over the log limit still go through; they just aren't recorded (Portkey pricing).
Limits: some Claude Code features need the anthropic-beta header, which Portkey forwards only after you add "forward_headers": ["anthropic-beta"] to a Portkey Config. With a Max plan login, costs show as $0 in Portkey because Anthropic bills directly.
Do gateways add fees on top of token prices?
Gateways add little or nothing per token; the differences are funding fees and fixed plans. Here is the same $1,000 month of Claude Code inference through each, using the published rates above:
| Gateway and funding | Gateway cost on $1,000 of inference | Basis |
|---|---|---|
| Claude apps gateway | $0 + your hosting | No fee; self-hosted |
| LiteLLM (open source) | $0 + your hosting | No license fee |
| Vercel AI Gateway credits | $0 (+ card processing if any) | Zero markup |
| Cloudflare, own Anthropic key | $0 | No markup on BYOK |
| Cloudflare Unified Billing | $50 | 5% x $1,000 |
| OpenRouter BYOK (under $25,000/month) | $0 | Free allowance |
| OpenRouter Standard credits | $55 | 5.5% x $1,000 |
| OpenRouter Business credits | $80 | 8% x $1,000 |
| Portkey free / Production | $0 / $49 | Flat plan, by logged requests |

The bigger number is the inference itself. If you want to see what your own Claude Code month costs at API rates before you pick, plug your token counts into the LLM cost calculator; our Claude Max vs API break-even shows when a subscription beats paying per token. Remember that a gateway credential moves a developer from their claude.ai subscription to API billing: "usage is billed to your organization's provider account at API rates" (Anthropic). For the full fee audit across more gateways, see AI gateway fees audited.
How do I point Claude Code at a proxy?
Set the base URL and the credential, verify with one request, then start claude. The credential variable decides the header: ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer, ANTHROPIC_API_KEY as x-api-key, and an apiKeyHelper command in both (Anthropic).
export ANTHROPIC_BASE_URL=https://llm-gateway.example.com
export ANTHROPIC_AUTH_TOKEN=sk-gateway-key
curl -sS -w '\n%{http_code}\n' -X POST "$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": 1, "messages": [{"role": "user", "content": "."}]}'A JSON body starting with {"id":"msg_ means it works. An unknown-model error also proves the URL and key are right. A 401 means the gateway reads the other header: switch between ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY. Inside Claude Code, /status should show an "Anthropic base URL" line with your gateway. To persist the values, put them in the env block of ~/.claude/settings.json, never in a committed .claude/settings.json.
Three optional variables matter on most gateways:
| Variable | Use it when |
|---|---|
| ANTHROPIC_CUSTOM_HEADERS | The gateway authenticates or routes on its own header (Cloudflare, Portkey, Vercel Max flow) |
| CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 | You want the gateway's models in the /model picker |
| CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 | Your network only allows egress to the gateway (this also turns off auto-updates) |
Which gateways support the Anthropic Messages format?
All six above do, natively: each serves /v1/messages and accepts Claude Code's request shape. That is the dividing line. A gateway that only speaks the OpenAI Chat Completions format cannot serve Claude Code, because Claude Code sends Anthropic Messages requests and expects the anthropic-beta header to reach the upstream. Claude Code can also reach a gateway through provider formats: ANTHROPIC_BEDROCK_BASE_URL with CLAUDE_CODE_USE_BEDROCK=1, or ANTHROPIC_VERTEX_BASE_URL with CLAUDE_CODE_USE_VERTEX=1, which Cloudflare supports for Bedrock and Vertex upstreams.
Can a gateway route Claude Code to cheaper models?
Technically yes, officially no. LiteLLM documents routing Claude Code to non-Anthropic models in its config, and Vercel and OpenRouter list other models in the picker. But Anthropic does not support non-Claude models through any gateway, and OpenRouter only guarantees Claude Code on the Anthropic first-party provider. Expect tool-calling and thinking features to break on other models.
The supported way to cut Claude Code cost is cheaper Claude models: pin background tasks with ANTHROPIC_DEFAULT_HAIKU_MODEL, and use a gateway's per-group allowlists (Claude apps gateway's availableModels) to keep Opus for the people who need it. Our coding agent cost-per-task leaderboard shows how far model choice moves the bill.
Which Claude Code gateway should you pick?
- You need SSO and data residency on your own cloud: Claude apps gateway. Budget a Linux host, Postgres and an OIDC app.
- You already run LiteLLM: keep it, and add the Anthropic model names to
model_list. - You want zero setup and one bill: Vercel AI Gateway (no markup) or OpenRouter (failover across Anthropic providers, 5.5% on credits).
- You are on Cloudflare and have your own Anthropic key: Cloudflare AI Gateway costs nothing extra.
- You want traces per coding session: Portkey, on the $49 plan once you pass 10,000 logged requests a month.
- You are one developer on a Claude subscription: you may not need a gateway at all; read what an LLM gateway is for first.
Where Vynaris fits
Vynaris is not on this list because it does not serve the native /v1/messages format yet, so we can't promise every Claude Code call works through it. Where it does fit is the rest of your stack: if your other agents and scripts use OpenAI-format clients (Cursor, Hermes, the OpenAI SDK), Vynaris gives them one endpoint with model: "auto" routing and a cost receipt on every response, at provider list price plus 3% on the first $500 a month and 1% after.
FAQ
What is a Claude Code gateway?
A Claude Code gateway is a proxy between Claude Code and a model provider that serves the Anthropic Messages API. Developers authenticate to it with a gateway credential, and it forwards requests with the organization's provider key, so budgets, usage tracking and audit logs live in one place.
How do I point Claude Code at a proxy?
Set ANTHROPIC_BASE_URL to the gateway address and ANTHROPIC_AUTH_TOKEN (bearer) or ANTHROPIC_API_KEY (x-api-key) to the gateway credential, in your shell or the env block of ~/.claude/settings.json. Run /status to confirm the base URL line appears.
Do gateways add fees on top of token prices?
Most add nothing per token. OpenRouter charges 5.5% on credit purchases (8% on Business), Cloudflare 5% on Unified Billing credits, and Portkey has a $49 monthly plan above 10,000 logged requests. Vercel, Cloudflare with your own key, LiteLLM and Claude apps gateway add no token fee.
Can I use my Claude Max subscription through a gateway?
Yes, on some gateways. Setting only ANTHROPIC_BASE_URL with no gateway credential keeps your claude.ai login active, so subscription limits apply; the gateway must forward the Authorization header. Vercel and Portkey document this flow with custom headers. Setting a gateway credential switches you to API billing instead.
Does Claude Code work with an OpenAI-compatible gateway?
Not directly. Claude Code sends Anthropic Messages requests to /v1/messages, so the gateway must serve that format. Gateways that only offer /v1/chat/completions need a translation layer such as LiteLLM in front.
Why does Claude Code return 401 through my gateway?
The credential is in the wrong variable. ANTHROPIC_AUTH_TOKEN goes out as Authorization: Bearer and ANTHROPIC_API_KEY as x-api-key; if your gateway reads the other header, the request is rejected. Switch variables and re-run the curl check.