Setup

Pointing Claude Code at
a custom API endpoint

As of 2026-10-07, per Anthropic's gateway docs, two variables are enough: ANTHROPIC_BASE_URL for the endpoint and ANTHROPIC_AUTH_TOKEN, sent as an Authorization: Bearer header (use ANTHROPIC_API_KEY if your gateway reads x-api-key); both can also live in the env block of settings.json. Since Claude Code 2.1.285, models with a 1M window (Opus 4.7+, Sonnet 5+, Fable) run at 1M behind a custom ANTHROPIC_BASE_URL, and the official advice is to run /autocompact 200k if your gateway stops at 200K. Cloud sessions aren't part of a gateway deployment, so gateway variables set there are not applied.

Updated 2026-10-08

Point this tool at the QCode endpoint — one key for Claude, GPT and Chinese models.

#ANTHROPIC_BASE_URL#ANTHROPIC_AUTH_TOKEN#settings.json#apiKeyHelper

Four things to know

2 variables

The minimum configuration

ANTHROPIC_BASE_URL points at the endpoint and ANTHROPIC_AUTH_TOKEN supplies the credential. In most cases that is all you need.

Authorization

Where the credential lands

Per the docs as of 2026-10-07: ANTHROPIC_AUTH_TOKEN goes in Authorization: Bearer, ANTHROPIC_API_KEY in x-api-key, and apiKeyHelper in both; a credential in the wrong variable reaches a header the gateway doesn't read and fails with 401.

settings.json

The second place to configure

If you would rather not use environment variables, put the same keys in the env block of settings.json — the shape maps one to one.

Not applied

Web and cloud sessions

Per the docs as of 2026-10-07: cloud sessions aren't part of a gateway deployment, and gateway variables set in a cloud session's environment configuration are not applied; if traffic must stay on the gateway, don't enable these surfaces for those users.

Why those two variables are enough

As of 2026-10-07, the answer is still two variables. Claude Code's egress is configurable: ANTHROPIC_BASE_URL decides where requests go and ANTHROPIC_AUTH_TOKEN decides what credential travels with them. The documentation puts the second one plainly — that environment variable is the step that places the key in the Authorization header, and the header is exactly what a gateway reads. So as long as your endpoint speaks the Anthropic protocol and authenticates on the Authorization header, the integration works with no client code changes.

The documented forms and the 2.1.285 change (checked 2026-10-07)

The first form is environment variables: set ANTHROPIC_BASE_URL to your endpoint and ANTHROPIC_AUTH_TOKEN to the credential. The second is the env block in settings.json, using the same key names. The documentation also describes apiKeyHelper: a command Claude Code runs to fetch your gateway credential instead of reading it from a static environment variable, which suits credentials that need rotating. Two further sections — adding gateway models to the model picker, and turning off traffic outside the gateway path — are worth reading for an enterprise deployment. Added 2026-10-07: the changelog entry for Claude Code 2.1.285 (released 2026-09-29) reads "Changed sessions behind a custom ANTHROPIC_BASE_URL to use the 1M context window of models that have one (Opus 4.7+, Sonnet 5+, Fable); run /autocompact 200k if your gateway stops at 200K". The model configuration page adds that Claude Code can't detect a lower limit that the gateway or the server behind it enforces.

Three steps to connect

Step 1

Set the two variables: ANTHROPIC_BASE_URL to the endpoint and ANTHROPIC_AUTH_TOKEN to the credential. Try it in a clean shell first rather than writing straight into your global configuration.

Step 2

Send one minimal request to confirm it works, and check that the model echoed in the response is the one you requested — that also tells you whether a rewriting layer sits in between.

Step 3

Once it is stable, make it permanent: move it into the env block of settings.json, or inject it in CI from your secret store (the documented CI shape passes the credential from secrets into ANTHROPIC_AUTH_TOKEN). If the credential needs rotating, switch to apiKeyHelper.

Documented by Anthropic vs ask your endpoint provider

Documented by Anthropic

① What ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN each do. ② That the credential travels in the Authorization header. ③ That the env block of settings.json is an equivalent second form. ④ That apiKeyHelper fetches the credential via a command instead of a static variable. ⑤ That cloud sessions (the web version) and Claude Code in Slack are not part of a gateway deployment, and gateway variables set in a cloud session's environment are not applied. ⑥ From Claude Code 2.1.285, models with a 1M window (Opus 4.7+, Sonnet 5+, Fable) run at 1M behind a custom ANTHROPIC_BASE_URL, with /autocompact 200k advised when a gateway stops at 200K (changelog wording, checked 2026-10-07).

Ask your endpoint provider

Whether the base URL should carry a path suffix, which model ids are served, whether 1M context and caching are supported, and what the concurrency ceiling is — all of that depends on the endpoint you are connecting to, and Anthropic's documentation will not answer it for them. On a 404, the path portion of your base URL is the first thing to check against their documentation; on a 401, confirm the credential is travelling in the Authorization header and not somewhere else. Ask about the context limit in particular: since 2.1.285 Claude Code budgets for 1M behind a custom endpoint but can't detect a lower gateway limit; if the gateway stops at 200K, run /autocompact 200k as the official advice says.

Two places to configure

Environment variables

Fastest to change and right for the first working attempt. The downside is that it is easy to lose — a new terminal or a different CI runner and it is gone — and the credential sits in the process environment. Good for validation and one-off tasks.

The env block in settings.json

Travels with the configuration rather than depending on your current shell, so it suits making things permanent. The credential is still written to disk in the clear, so if it needs rotating or should not be on disk, use apiKeyHelper instead: a command Claude Code calls to fetch the credential when it needs one.

The three usual sticking points

① Set but not taking effect: confirm the variable is visible to the process you are actually running, and that it is not shadowed by a same-named key in settings.json — when both exist, the effective load order decides. ② Not taking effect on web or cloud sessions: this is documented behaviour; the current gateway docs say cloud sessions are not part of a gateway deployment, so gateway variables set there are not applied. ③ Account-identity features behaving oddly: the documentation notes that a session authenticated with ANTHROPIC_AUTH_TOKEN can get an availability-check result that disagrees with the organisation's setting, because that check requires a claude.ai login or an Anthropic API key.

On QCode

As of 2026-10-07, QCode's docs say connecting Claude Code takes exactly the two variables above: ANTHROPIC_BASE_URL set to https://api.qcode.cc/api (no trailing slash) and ANTHROPIC_AUTH_TOKEN set to your key starting with cr_; a tool that only reads ANTHROPIC_API_KEY works with the same cr_ key. Claude models only work on the Anthropic-protocol endpoint. This page makes no promise about the context limit of any model on QCode; if you hit a context-limit error, follow Claude Code's official advice and lower the threshold with /autocompact. Once connected, do two things straight away: send one minimal request and check that the echoed model matches what you requested, and reconcile usage against your charges once. Billing is per token; see /models for each model's price.

What changes once ANTHROPIC_BASE_URL points at a gateway

Both caveats sit in the official ANTHROPIC_BASE_URL entry under one condition: the value points at a non-first-party host. QCode is such a host, so both apply to this route as well.

MCP tool search is off by default

The official entry is blunt: when the variable points at a non-first-party host, MCP tool search is disabled by default; if your proxy forwards tool_reference blocks, set ENABLE_TOOL_SEARCH=true and verify it once. Where the proxy does not forward them, staying off costs you only that retrieval shortcut — ordinary tool calls and messages are unaffected. Checked 2026-10-07.

Remote Control is disabled

Same document: as of v2.1.196, Remote Control stops working when the variable points at a host other than api.anthropic.com, matching how it behaves on Amazon Bedrock, Google Cloud Agent Platform and Microsoft Foundry. If you run remote-control sessions from a phone, treat this as a known boundary rather than something to debug. Checked 2026-10-07.

Which header the credential rides on

The official split: if your gateway team says bearer token or Authorization header, set ANTHROPIC_AUTH_TOKEN; if they say API key or x-api-key, set ANTHROPIC_API_KEY; when nobody says which, the docs start you on ANTHROPIC_AUTH_TOKEN and use a minimal request to see whether to switch. QCode accepts either — the only question is which variable you write. Checked 2026-10-07.

These three notes come from the ANTHROPIC_BASE_URL entry and the LLM gateway connect page in Anthropic's docs, checked 2026-10-07; both behaviours track the Claude Code version you run, so the live documents stay the authority.

FAQ

What is the minimum set of variables?

Two: ANTHROPIC_BASE_URL for the endpoint and ANTHROPIC_AUTH_TOKEN for the credential. The documentation states that the latter is the variable that places the key in the Authorization header.

Should the base URL include a path suffix?

That depends on the endpoint you are connecting to; Anthropic's documentation does not answer it for them. The quickest way to settle it is to follow the provider's documentation and send one minimal request — if you get a 404, the path portion is the first thing to check. For QCode, the documented value is https://api.qcode.cc/api, with no trailing slash.

Can I avoid environment variables entirely?

Yes — put the same keys in the env block of settings.json. If the credential needs rotating, or you would rather it not sit on disk in the clear, use apiKeyHelper instead: a command Claude Code runs to fetch the credential.

Why does it not take effect on the web version?

This is documented behaviour. As of 2026-10-07 the official gateway docs say that Claude Code in Slack and cloud sessions (the web version) are not part of a gateway deployment, and gateway variables set in a cloud session's environment configuration are not applied; if traffic must stay on your gateway, don't enable these surfaces for those users. The version captured on 2026-09-22 also said both always use Anthropic's API; the current docs no longer include that half-sentence.

How do I configure it in CI?

The documented shape passes the credential from your secret store into ANTHROPIC_AUTH_TOKEN, with the base URL set as usual. Do not put the credential into a configuration file in the repository — that is no different from hard-coding it.

What is the first thing to verify once it connects?

That the model echoed in the response is the one you requested. If it carries a prefix, suffix or provider name that was not in your request, a rewriting layer sits in between. Not necessarily bad, but it determines how you should attribute what you later see on the bill.

Sources

What the two environment variables do, which header each credential uses, the settings.json env block form, the definition of apiKeyHelper, and that cloud sessions do not go through a gateway: Anthropic's documentation "Connect Claude Code to an LLM gateway" (code.claude.com/docs/en/llm-gateway-connect, first fetched 2026-09-02, rechecked 2026-10-07). The ANTHROPIC_BASE_URL entry: the Claude Code environment variables page (fetched 2026-10-07). 1M context and /autocompact 200k: the Claude Code changelog (CHANGELOG.md in the anthropics/claude-code GitHub repository, the 2.1.285 entry) and the model configuration page, with the release date from the same repository's GitHub Releases, all fetched 2026-10-07. QCode setup: the environment variables and endpoints pages on docs.qcode.cc (fetched 2026-10-07). The path shape, available models and limits of any specific endpoint depend on the provider you connect to; this page does not answer for them.

Two variables, tried in a clean shell first

Once it works, verify the echoed model and reconcile usage before you commit it to configuration.

Further reading

The official documentation quoted here was last checked on 2026-10-07 and may change; Anthropic's pages take precedence. The path shape, model set and limits of any specific endpoint are governed by that provider's documentation; model availability is whatever /models shows.

Try first, then decide

Not sure which tier? Start with Starter ($8.57/mo) and upgrade when you're happy — the unused value of the old plan goes back to your balance.