Omniscio

OmniscioGuidesClaude Code through an LLM gateway

Claude Code through an LLM gateway

This page is the client side: getting one developer's Claude Code onto a gateway your organization already runs, and reading the errors that follow. If your machine cannot reach Anthropic at all, that is a network problem with its own page, Claude Code behind a corporate proxy.

Last checked against Anthropic's documentation on November 24, 2026. By the Omniscio team. Updated .

Check whether your administrator already set it up

Administrators can hand the gateway address and credential to every machine through managed settings, device management or an apiKeyHelper, in which case there is nothing for you to configure. To find out, run claude and then /status, which opens on the Status tab, and read two lines.

  • Anthropic base URL appears only when a gateway address is set. If the line is missing, nothing points Claude Code at a gateway.
  • Auth token or API key, naming ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY or an apiKeyHelper, means a gateway credential is active. A Login method line naming a claude.ai account instead means no gateway credential reached the session.

The third check is the honest one: send a prompt. A normal answer, with no error, means the connection works. If both lines look right and the prompt still fails, skip ahead to the errors a gateway causes.

Set the address and the credential

Ask your gateway team for two things: the base URL and a credential. The credential goes in one of three places, and the choice is not cosmetic, because each one sends the value in a different HTTP header.

Set it inSend the request headerUse it when your gateway team said
ANTHROPIC_AUTH_TOKENAuthorization: Bearerbearer token, or Authorization header
ANTHROPIC_API_KEYx-api-keyAPI key, or x-api-key
apiKeyHelper settingboththe credential rotates, or comes from a vault

If nobody told you which kind it is, start with ANTHROPIC_AUTH_TOKEN. The verification step below tells you whether that was right: a 401 is the signal to switch variables and try again.

Two places to put them, and one place never to

A shell export lasts for one terminal session and the programs started from it, so an editor launched from the dock or the Start menu will not see it. A settings file's env block applies everywhere Claude Code runs on that machine. The desktop app is one surface it does not reach, and the VS Code extension and cloud sessions fall short in their own ways — both are covered below. When both set the same variable, the settings file wins.

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://llm-gateway.example.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-gateway-key"
  }
}

Put that block in ~/.claude/settings.json to reach every project, or in a project's .claude/settings.local.json to reach one. On Windows the user file is %USERPROFILE%\.claude\settings.json.

Keep the credential out of a project's .claude/settings.json. That file is committed and shared with everyone who clones the repository, so a key in it is a leaked key. Anthropic's own warning is that blunt.

What happens to the login you already had

ANTHROPIC_AUTH_TOKEN takes precedence immediately, while ANTHROPIC_API_KEY asks once, in interactive mode, before it takes over. If startup warns that two credential sources are set, ending in auth may not work as expected, unset the variable to keep the saved login or run /logout to keep the gateway credential. Older versions word the same warning as Auth conflict: Both a token (SOURCE) and an API key (SOURCE) are set.

Prove the gateway works before Claude Code is involved

Send a one-token request straight to the gateway with the same two variables exported in your shell. If it fails here, the problem is the address, the credential or the network path, and Claude Code is not part of it.

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": "."}]}'

Read the answer literally. A JSON body that starts with {"id":"msg_ and carries a "content" array means the gateway is reachable and the credential works. An error naming an unknown model also proves both, because the gateway authenticated the request before it rejected the model name, so you do not have to find a model it serves. A 401 means the credential was rejected.

If your gateway reads keys from x-api-key rather than a bearer header, swap the Authorization line for -H "x-api-key: $ANTHROPIC_API_KEY".

Now start claude from that same shell and send a message. /status should show your gateway address on the Anthropic base URL line and the variable you set on the Auth token or API key line. If the base URL line is absent, the variable never reached the session.

Where the setting does not carry

The terminal reads any of the places above. Four other surfaces need their own attention, and each one is a different story.

Background agents. A shell export does not reliably reach background agents hosted by the supervisor, so any gateway they must always route through belongs in a settings file's env block.

The VS Code extension checks credentials from its own claudeCode.environmentVariables setting before it launches, so that is the reliable place for a gateway credential. Values in ~/.claude/settings.json reach the process the extension spawns, but not the extension's own login check.

{
  "claudeCode.environmentVariables": [
    { "name": "ANTHROPIC_BASE_URL", "value": "https://llm-gateway.example.com" },
    { "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-gateway-key" }
  ]
}

The desktop app does not read ANTHROPIC_BASE_URL or settings.json at all. It routes through a gateway from its third-party inference configuration, distributed by an administrator or entered under Help → Troubleshooting → Enable Developer Mode and then Developer → Configure Third-Party Inference. An administrator-distributed configuration takes precedence and makes that form read-only.

Two things disappear while a gateway configuration is active in the desktop app: the environment selector stops offering Anthropic-hosted cloud environments, and Remote Control is unavailable.

GitHub Actions reads ANTHROPIC_BASE_URL and ANTHROPIC_CUSTOM_HEADERS from the workflow's env block. For a gateway that reads x-api-key, the credential goes in the action's anthropic_api_key input, which the action sets as ANTHROPIC_API_KEY. For a bearer-token gateway, pass the same secret twice: as anthropic_api_key, which only satisfies the action's launch check, and as ANTHROPIC_AUTH_TOKEN in the workflow's env block, which is what puts it in the Authorization header the gateway reads.

The errors a gateway causes, and what each one means

Most of these read like an Anthropic outage and are not one. The message names the layer that refused, and the fix is nearly always at that layer rather than in Claude Code.

What you seeWhat it meansWhat to do
A startup warning that two credential sources are set, ending auth may not work as expectedA gateway credential and a saved login are both activeUnset the variable to keep the login, or run /logout to keep the gateway credential
401 naming an invalid or unrecognized tokenThe credential is not one the gateway issued, or it sits in a header the gateway does not readMatch the variable to the credential kind, and regenerate the key at the gateway if it was revoked
Your apiKeyHelper script is failingThe helper did not produce a usable key, so requests carry a placeholderRun that command yourself to see why, and re-authenticate with your credential provider
API returned an empty or malformed response (HTTP 200)The gateway or a proxy in front of it answered with something that is not an API response, often an HTML error or login pageRun the curl test: it shows the same thing, and points at the route that answers wrongly
400 naming context_management, Extra inputs are not permitted, or another unrecognized fieldThe gateway forwards to an upstream that rejects fields Claude Code sends to Anthropic-format endpointsSet CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1, which suppresses most pre-release fields
400 stating a context or token limit in the gateway's own wordsThe gateway enforces a smaller context and rewrites the upstream error, so Claude Code does not recognize a too-long prompt and does not compact and retryRun /compact; to prevent it, set CLAUDE_CODE_AUTO_COMPACT_WINDOW to the gateway's limit when that limit is 100,000 tokens or more, and set CLAUDE_CODE_MAX_OUTPUT_TOKENS below the model's output limit
403 with an HTML body, while the gateway's own logs show no requestA web application firewall or reverse proxy blocked the request body before the gateway saw it; prompts carry XML-style tags and code that match cross-site-scripting body rulesExempt the gateway's /v1/messages path from request-body inspection
Certificate or TLS errors such as SSL certificate verification failed, while curl succeedsClaude Code's runtime does not trust the certificate authority curl uses, which is common behind TLS-inspection proxiesPoint NODE_EXTRA_CA_CERTS at the CA bundle path
Models missing from the /model pickerThe gateway's model names are not in Claude Code's built-in listTurn on gateway model discovery, or add the names with the model configuration variables

The clamp is the one detail the table cannot carry: Anthropic clamps CLAUDE_CODE_AUTO_COMPACT_WINDOW to at least 100,000 tokens, so a gateway limit below that cannot be matched, and compacting by hand stays the only recovery there.

If you are the one rolling it out

Anthropic's rollout order is four steps: deploy the gateway and give it the provider credential, issue each developer their own gateway credential so usage is attributed and offboarding revokes one thing, distribute the base URL and credential through managed settings so developers configure nothing, and have each developer check for the configuration before they depend on it.

To make the gateway the only place a managed machine may send requests, set allowedProviders to ["customEndpoint"] in the same managed settings file and put the gateway's ANTHROPIC_BASE_URL in that file's env block. Claude Code then refuses a session pointed anywhere else, including at Anthropic directly or at a developer's own proxy. That needs Claude Code v2.1.285 or later.

Two limits worth stating plainly before you promise anything. The gateway becomes infrastructure you operate: Claude Code adds capabilities with each release, and a gateway that does not forward them breaks the matching features, so it has to be kept current. And Anthropic neither endorses nor maintains third-party gateway products, and does not support routing Claude Code to non-Claude models through any gateway.

One conflict to plan around: if managed settings set forceLoginMethod or forceLoginOrgUUID, they cannot coexist with ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN or apiKeyHelper. You either ship the sign-in those settings require, or remove them and ship gateway credentials.

Where these answers come from

  • Connect Claude Code to an LLM gateway, read November 24, 2026: the credential table, the settings-file and shell precedence, the curl test and how to read it, the surface differences, and the troubleshooting table quoted in this page's error section.
  • Other LLM gateways: what a gateway provides, the rollout order, allowedProviders, and the statement that Anthropic does not endorse third-party gateway products.
  • Gateway compatibility: what a gateway has to forward for Claude Code's features to keep working.

Common questions

Which variable holds my gateway credential?

It depends on what your gateway team calls the credential. A bearer token or authorization header goes in ANTHROPIC_AUTH_TOKEN, an API key or x-api-key goes in ANTHROPIC_API_KEY, and a credential that rotates or lives in a vault goes through apiKeyHelper. If nobody told you which, set ANTHROPIC_AUTH_TOKEN and run Anthropic's curl test: a 401 means you picked the wrong one, so switch and re-export.

Why does Claude Code still ask me to log in when the gateway works?

A reachable base URL is not a credential. In an interactive session, an env block in a project's .claude/settings.json or .claude/settings.local.json applies only after the first-run wizard and the trust prompt, so Claude Code reaches the login screen first. Set ANTHROPIC_AUTH_TOKEN somewhere it reads before that: a shell export, the env block in ~/.claude/settings.json, or managed settings.

Does the gateway setting reach the desktop app and background agents?

Not the same way. Shell exports do not reliably reach background agents hosted by the supervisor, so a gateway those must always use belongs in a settings file's env block. The desktop app ignores ANTHROPIC_BASE_URL and settings.json entirely and reads gateway routing from its third-party inference configuration instead, which an administrator distributes or you enter under Developer settings.

Why does everything 400 through the gateway but work directly against Anthropic?

Claude Code sends fields and beta headers that a gateway or its upstream may not recognize. Anthropic's first move is CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1, which suppresses most pre-release fields. A 403 with an HTML body and no matching request in the gateway's own logs is different: a web application firewall rejected the request body before it arrived, and the /v1/messages path has to be exempt from body inspection.