Skip to content

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:

  1. POST /v1/messages (with ?beta=true). Claude Code appends /v1/messages to ANTHROPIC_BASE_URL itself. Appending /v1 to a root base URL produces /v1/v1/messages and triggers an HTTP 404.
  2. 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) and message_delta.
  3. Multi-turn tool calling. Every file read, grep, edit and bash command is an Anthropic tool_use / tool_result exchange. Dropping or reordering tool IDs causes immediate 400 invalid_request_error failures on the next turn.
  4. Extended / adaptive thinking signatures. Current Claude models (claude-opus-5-5, claude-sonnet-5-5, claude-haiku-5-5) replay thinking and redacted_thinking blocks with cryptographic signature fields across tool turns. A gateway that mutates or strips those blocks breaks multi-step tool loops.
  5. 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. Preserving cache_control breakpoints keeps repeated prefixes on cache-read rates (0.1x on Anthropic's schedule) instead of full input billing.

Comparison Table: Gateways with Anthropic Messages Support ​

OptionCategoryDocumented ANTHROPIC_BASE_URLAuth variable / headerPrompt cachingBring your own keys (BYOK)Self-hostableNotes from official docs
OpenRouterHosted aggregatorhttps://openrouter.ai/apiANTHROPIC_AUTH_TOKEN (Bearer)Provider pass-through (0.1x read on Anthropic)OptionalNoClaude Code guide notes official support is scoped to the Anthropic first-party provider
RequestyHosted gatewaySee Requesty docs (Anthropic Messages route)Gateway key (see docs)Documented on supported routesOptionalNoPrepaid USD balance; 5% service fee added on top-up (checked 2026-11-14)
Vercel AI GatewayHosted gatewayhttps://ai-gateway.vercel.shGateway key (Bearer / see docs)Provider pass-throughOptionalNoRequires Vercel account; prepaid credits at provider list price, no token markup
byesuHosted gatewayhttps://byesu.comANTHROPIC_AUTH_TOKEN (Bearer)Uniform 0.1x cache read across cached modelsNot offeredNoPay-as-you-go, no subscription; public live status & weekly benchmarks
LiteLLM ProxySelf-hosted / OSS proxyhttp(s)://<your-host> (/v1/messages pass-through or translation)ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY (virtual key)Preserved on Anthropic pass-throughYes (required)Yes (Docker / Helm)Translates non-Claude models too, with caveats on thinking/caching features
PortkeyOSS gateway + managed cloudPortkey gateway URL (Anthropic Messages spec)Portkey virtual / API key headersSupported in gateway configYes (required)Yes (@portkey-ai/gateway)Cloud plans tiered by recorded logs/month; inference billed by your providers
Bedrock / Vertex / FoundryCloud-native AnthropicNative SDK flags (CLAUDE_CODE_USE_BEDROCK=1, etc.)Cloud IAM (AWS_*, GCP ADC, Azure)Supported per cloud region/modelUses your cloud accountNo (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/messages in the Anthropic Messages format, and its Claude Code integration guide sets ANTHROPIC_BASE_URL=https://openrouter.ai/api (note the /api suffix, because OpenRouter mounts /v1/messages under /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.sh and 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/messages endpoint directly at https://byesu.com (plus OpenAI-compatible /v1/chat/completions and /v1/responses at https://byesu.com/v1). Set ANTHROPIC_BASE_URL=https://byesu.com and ANTHROPIC_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, output 5x, prompt-cache read 0.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/messages both as a direct Anthropic pass-through (preserving native Claude thinking and cache_control fields) 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):

json
{
  "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.com with your chosen gateway's Anthropic base URL (for example https://openrouter.ai/api on OpenRouter, or your internal LiteLLM host). Run unset ANTHROPIC_API_KEY in your shell if an old direct key is still exported.

Before launching claude, verify routing and auth in one second with curl:

bash
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 200 with "id":"msg_..." → endpoint, auth header and model ID all match; launch claude and run /status to confirm.
  • HTTP 404 mentioning /v1/v1/messages → remove the trailing /v1 from ANTHROPIC_BASE_URL.
  • HTTP 401 → wrong variable (ANTHROPIC_AUTH_TOKEN vs ANTHROPIC_API_KEY), stale .env export, or disabled token. See Claude Code Custom ANTHROPIC_BASE_URL Errors for every failure mode.

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 ​

Got a problem? Contact support or join our group.