Third-Party API Gateways for Claude Code: Anthropic /v1/messages Support Compared
Short answer: Claude Code speaks the Anthropic Messages API (POST /v1/messages), not OpenAI /v1/chat/completions. To connect Claude Code to a third-party gateway without an Anthropic subscription, choose a gateway that exposes an Anthropic Messages endpoint, set ANTHROPIC_BASE_URL to its base URL (without /v1), and pass your token in ANTHROPIC_AUTH_TOKEN (sent as Authorization: Bearer) or ANTHROPIC_API_KEY (sent as X-Api-Key). Hosted options with documented Anthropic Messages support include OpenRouter, Requesty, Vercel AI Gateway and byesu; self-hosted / bring-your-own-key options include LiteLLM Proxy and Portkey; cloud-contract teams can also use Amazon Bedrock, Google Vertex AI or Microsoft Foundry natively.
Last verified: 2026-11-17 (competitor pages checked 2026-11-14 to 2026-11-17; sources listed under Sources). Statements about third-party products cite only what their official docs and pricing pages state. Where an official page did not state a detail, the table marks it Not confirmed on pages read. This guide is published by byesu, so evaluate the byesu entry with that context in mind.
What Claude Code Actually Requires from a Gateway
Per Anthropic's LLM gateway protocol and gateway connection guide, an OpenAI-only /v1/chat/completions proxy will not work out of the box. A gateway sitting behind ANTHROPIC_BASE_URL needs to handle five protocol details cleanly:
POST /v1/messages(with?beta=true). Claude Code appends/v1/messagestoANTHROPIC_BASE_URLitself. Appending/v1to a root base URL produces/v1/v1/messagesand triggers an HTTP 404.- Streaming Server-Sent Events (SSE). Interactive turns stream
message_start,content_block_start,content_block_delta(text_delta,input_json_delta,thinking_delta,signature_delta) andmessage_delta. - Multi-turn tool calling. Every file read, grep, edit and bash command is an Anthropic
tool_use/tool_resultexchange. Dropping or reordering tool IDs causes immediate400 invalid_request_errorfailures on the next turn. - Extended / adaptive thinking signatures. Current Claude models (
claude-opus-5-5,claude-sonnet-5-5,claude-haiku-5-5) replaythinkingandredacted_thinkingblocks with cryptographicsignaturefields across tool turns. A gateway that mutates or strips those blocks breaks multi-step tool loops. - Prompt caching (
cache_control) and background model IDs. Claude Code resends its system prompt, tool definitions and message thread on every turn, and also uses a fast model slot (ANTHROPIC_DEFAULT_HAIKU_MODEL) for background tasks. Preservingcache_controlbreakpoints keeps repeated prefixes on cache-read rates (0.1xon Anthropic's schedule) instead of full input billing.
Comparison Table: Gateways with Anthropic Messages Support
| Option | Category | Documented ANTHROPIC_BASE_URL | Auth variable / header | Prompt caching | Bring your own keys (BYOK) | Self-hostable | Notes from official docs |
|---|---|---|---|---|---|---|---|
| OpenRouter | Hosted aggregator | https://openrouter.ai/api | ANTHROPIC_AUTH_TOKEN (Bearer) | Provider pass-through (0.1x read on Anthropic) | Optional | No | Claude Code guide notes official support is scoped to the Anthropic first-party provider |
| Requesty | Hosted gateway | See Requesty docs (Anthropic Messages route) | Gateway key (see docs) | Documented on supported routes | Optional | No | Prepaid USD balance; 5% service fee added on top-up (checked 2026-11-14) |
| Vercel AI Gateway | Hosted gateway | https://ai-gateway.vercel.sh | Gateway key (Bearer / see docs) | Provider pass-through | Optional | No | Requires Vercel account; prepaid credits at provider list price, no token markup |
| byesu | Hosted gateway | https://byesu.com | ANTHROPIC_AUTH_TOKEN (Bearer) | Uniform 0.1x cache read across cached models | Not offered | No | Pay-as-you-go, no subscription; public live status & weekly benchmarks |
| LiteLLM Proxy | Self-hosted / OSS proxy | http(s)://<your-host> (/v1/messages pass-through or translation) | ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY (virtual key) | Preserved on Anthropic pass-through | Yes (required) | Yes (Docker / Helm) | Translates non-Claude models too, with caveats on thinking/caching features |
| Portkey | OSS gateway + managed cloud | Portkey gateway URL (Anthropic Messages spec) | Portkey virtual / API key headers | Supported in gateway config | Yes (required) | Yes (@portkey-ai/gateway) | Cloud plans tiered by recorded logs/month; inference billed by your providers |
| Bedrock / Vertex / Foundry | Cloud-native Anthropic | Native SDK flags (CLAUDE_CODE_USE_BEDROCK=1, etc.) | Cloud IAM (AWS_*, GCP ADC, Azure) | Supported per cloud region/model | Uses your cloud account | No (managed cloud) | Built into Claude Code for AWS, GCP and Azure enterprise billing |
Option-by-Option Breakdown
1. Hosted Gateways (One Key, One Balance)
Choose this group when you do not want to manage separate Anthropic, OpenAI and Google API accounts, and want a ready-made endpoint in two minutes.
OpenRouter
- How it connects: OpenRouter's API reference documents
POST /api/v1/messagesin the Anthropic Messages format, and its Claude Code integration guide setsANTHROPIC_BASE_URL=https://openrouter.ai/api(note the/apisuffix, because OpenRouter mounts/v1/messagesunder/api). - Important caveat: OpenRouter's Claude Code guide states that Claude Code compatibility is documented for the Anthropic first-party provider and recommends pinning Anthropic first in provider routing.
- Billing (checked 2026-11-17): Inference runs at provider list price; credit purchases carry a 5.5% fee on Standard and 8% on Business. BYOK is available (first $25,000/month of list-price inference has no fee, 5% above that). See byesu vs OpenRouter for a full comparison.
Requesty
- How it connects: Requesty's inference API docs list Anthropic Messages alongside OpenAI Chat Completions and OpenAI Responses, with routing policies (fallbacks, latency routing), spend budgets and an optional EU endpoint in Frankfurt.
- Billing (checked 2026-11-14): Prepaid USD balance with a 5% service fee added on each top-up; optional BYOK for supported providers.
Vercel AI Gateway
- How it connects: Hosted at
https://ai-gateway.vercel.shand callable via Anthropic Messages as well as the AI SDK, Chat Completions and Responses — even if your app or CLI runs outside Vercel. - Billing (checked 2026-11-14): Requires a Vercel account; prepaid credits are billed at provider list price with no token markup (payment processing fees and paid add-ons are separate).
byesu
- How it connects: Exposes an Anthropic-native
/v1/messagesendpoint directly athttps://byesu.com(plus OpenAI-compatible/v1/chat/completionsand/v1/responsesathttps://byesu.com/v1). SetANTHROPIC_BASE_URL=https://byesu.comandANTHROPIC_AUTH_TOKEN=sk-...in~/.claude/settings.json— full step-by-step in Connecting Claude Code CLI. - Billing & observability: Pay-as-you-go per token with no subscription, a uniform multiplier structure (input
1x, output5x, prompt-cache read0.1x), live billed prices visible in the console, and top-ups via USDT or Alipay. Route health and latency are published openly on the status page and weekly latency benchmarks. - Trade-offs to know: Curated catalog (smaller than OpenRouter's 600+ models), no BYOK, and no self-hosted edition.
2. Self-Hosted and Bring-Your-Own-Key Proxies
Choose this group when your company already holds Anthropic, Bedrock, Vertex or OpenAI contracts and needs centralized virtual keys, per-engineer budgets, or self-hosted audit logs.
LiteLLM Proxy
- How it connects: Deployed on your own Docker, Kubernetes/Helm or VM stack in front of your provider keys. LiteLLM documents
/v1/messagesboth as a direct Anthropic pass-through (preserving native Claude thinking andcache_controlfields) and as an adapter layer that maps Anthropic Messages calls onto non-Anthropic models. - Trade-offs: You operate the proxy and its Postgres database (needed for virtual keys and spend tracking); SSO and enterprise audit features require a commercial license. You can also stack LiteLLM locally in front of a hosted gateway — see byesu vs LiteLLM.
Portkey
- How it connects: Open-source MIT gateway (
npx @portkey-ai/gateway) plus a managed cloud control plane. Portkey's Universal API documents the Anthropic Messages specification alongside OpenAI Chat Completions and Responses, with virtual keys, guardrails and fallback rules stored in Model Catalog. - Billing (checked 2026-11-14): Provider keys and inference bills stay with your providers; Portkey Cloud tiers are based on monthly recorded log volume (with a free developer tier).
3. Cloud-Native Anthropic Endpoints (AWS, GCP, Azure)
If your goal is simply consolidated enterprise cloud billing rather than multi-vendor aggregation, Claude Code has first-party flags built in (CLAUDE_CODE_USE_BEDROCK=1 for Amazon Bedrock, CLAUDE_CODE_USE_VERTEX=1 for Google Vertex AI, CLAUDE_CODE_USE_FOUNDRY=1 for Microsoft Foundry). These use cloud IAM credentials directly instead of ANTHROPIC_BASE_URL; check Anthropic's cloud docs for regional model availability and prompt-caching parity.
Standard Setup & Preflight Test (~/.claude/settings.json)
Whichever Anthropic-compatible gateway you choose, put the configuration in ~/.claude/settings.json rather than project-level .claude/settings.json (which can be committed to git by mistake):
{
"env": {
"ANTHROPIC_BASE_URL": "https://byesu.com",
"ANTHROPIC_AUTH_TOKEN": "sk-your-gateway-token",
"ANTHROPIC_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"
}
}Replace
https://byesu.comwith your chosen gateway's Anthropic base URL (for examplehttps://openrouter.ai/apion OpenRouter, or your internal LiteLLM host). Rununset ANTHROPIC_API_KEYin your shell if an old direct key is still exported.
Before launching claude, verify routing and auth in one second with curl:
curl -sS -w '\nHTTP %{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-5-5",
"max_tokens": 16,
"messages": [{"role": "user", "content": "Reply with ok"}]
}'HTTP 200with"id":"msg_..."→ endpoint, auth header and model ID all match; launchclaudeand run/statusto confirm.HTTP 404mentioning/v1/v1/messages→ remove the trailing/v1fromANTHROPIC_BASE_URL.HTTP 401→ wrong variable (ANTHROPIC_AUTH_TOKENvsANTHROPIC_API_KEY), stale.envexport, or disabled token. See Claude Code CustomANTHROPIC_BASE_URLErrors for every failure mode.
Related Guides
- Connecting Claude Code CLI — one-click setup script and manual
~/.claude/settings.jsonwalkthrough - Claude Code Custom
ANTHROPIC_BASE_URLErrors — fixing/v1/v1/messages404s, auth conflicts and model alias errors - Why Claude Message Threads Break Through Third-Party Gateways — thinking signatures,
tool_resultordering andcache_control - Claude Code Token Usage & Prompt Caching Breakdown — how repeated context affects session cost
- OpenRouter Alternatives in 2026 & byesu vs OpenRouter
FAQ
Can Claude Code connect to a third-party API gateway?
Yes, as long as the gateway exposes an Anthropic Messages-compatible POST /v1/messages endpoint. Claude Code does not speak OpenAI /v1/chat/completions natively; you point ANTHROPIC_BASE_URL at the gateway root (without /v1) and pass your credential in ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY.
Which API gateways support the Anthropic Messages format for Claude Code?
Based on official documentation checked in November 2026: hosted gateways that document an Anthropic Messages endpoint include OpenRouter (https://openrouter.ai/api), Requesty, Vercel AI Gateway (https://ai-gateway.vercel.sh) and byesu (https://byesu.com). Self-hosted or bring-your-own-key gateways that document Anthropic Messages support include LiteLLM Proxy and Portkey. Enterprise cloud teams can also route Claude Code natively to Amazon Bedrock, Google Vertex AI or Microsoft Foundry.
Why does Claude Code return 404 when I set ANTHROPIC_BASE_URL?
Claude Code automatically appends /v1/messages to ANTHROPIC_BASE_URL. If your base URL ends in /v1 (such as https://example.com/v1), requests go to /v1/v1/messages and return 404, which Claude Code often surfaces as a model error. Remove the trailing /v1 unless the gateway explicitly mounts its Anthropic route under an extra path prefix like OpenRouter's /api.
Should I set ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY for a gateway?
Check which HTTP header your gateway reads. ANTHROPIC_AUTH_TOKEN sends Authorization: Bearer and applies immediately with no interactive prompt; ANTHROPIC_API_KEY sends X-Api-Key and asks for one-time approval in interactive mode. Set only one variable and unset the other so stale shell exports do not take precedence.
Why does prompt caching support matter when choosing a Claude Code gateway?
Every turn in a Claude Code session resends the system prompt, tool schemas and full conversation history. On gateways that preserve Anthropic prompt caching (0.1x cache reads, 1.25x or 2x cache writes), repeated prefixes are billed at cache-read rates; if a translation proxy strips cache_control blocks, every turn pays full input price.
Sources
- Anthropic Claude Code docs: LLM gateway protocol, Connect through an LLM gateway, Authentication precedence, Model configuration
- OpenRouter (checked 2026-11-17): Claude Code integration guide, API reference, pricing
- Requesty (checked 2026-11-14): inference APIs, billing
- Vercel AI Gateway (checked 2026-11-14): overview, pricing
- LiteLLM (checked 2026-11-14): proxy overview, Anthropic pass-through & endpoints
- Portkey (checked 2026-11-14): AI Gateway, pricing