Learning resourcesReviewed · Anthropic

Connect Claude Code to an LLM gateway

This guide helps developers connect Claude Code to their organization's LLM gateway, but it assumes the gateway already exists. It explains credentials, settings, connection checks and troubleshooting, with separate instructions for the CLI, VS Code, desktop app, GitHub Actions and Agent SDK.

Researched 25 Nov 2026

In short.

This guide explains Claude Code gateway setup for developers, but routing model requests through a gateway does not cover every background connection or hosted feature. It documents credential headers, settings precedence, configuration across interfaces, rotating credentials and provider-specific routes. Its strongest practical detail is explaining why a working terminal configuration may fail in an editor, background agent or automation. Connectivity, compatibility, security and performance have not been assessed through execution, and costs are unknown.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete selected page at [https://code.claude.com/docs/en/llm-gateway-connect.md], including interface-specific settings, provider routes, troubleshooting, version caveats, credential-handling warnings and external-traffic notices. Linked documentation and repositories are excluded. No commands or code were executed; connectivity, compatibility, security and performance remain untested. Costs and redistribution rights are not established.

The overview

Identity

Connect Claude Code to an LLM gateway is a Claude Code documentation page at [https://code.claude.com/docs/en/llm-gateway-connect.md]. It is a setup and troubleshooting guide, rather than a gateway service or deployable gateway implementation.

The page defines an LLM gateway as an organization-operated proxy between Claude Code and the model provider. Developers authenticate to it with organization-issued credentials instead of their personal claude.ai login.

Assessment

The guide is useful when a gateway already exists and a developer needs to connect, confirm an administrator's configuration or diagnose failures. Its concrete distinctions between credential headers, settings locations and application startup checks make it more useful than a basic base-URL example.

It does not establish whether a particular gateway is reliable, secure or compatible with every Claude Code feature. It supplies no measured latency, reliability or model-quality results, and does not provide deployment instructions for building the gateway itself.

Users

The primary audience is developers whose organization operates an LLM gateway. Bash, Zsh and PowerShell examples support individual setup, while separate sections address VS Code users, desktop users, GitHub Actions maintainers and developers embedding the Agent SDK.

Beginners receive a sequence for checking existing settings and connecting manually. Experienced developers receive details about HTTP headers, environment inheritance, provider request formats and schema-related failures. Administrators planning deployment are directed to a separate rollout guide.

Capabilities

The page covers detecting an existing managed configuration, setting the gateway address and credential, making a direct verification request, checking the active configuration with /status and resolving common errors.

Additional topics include tenant or routing headers, gateway model discovery, credentials fetched by apiKeyHelper, controls for nonessential external traffic and provider-specific routes for Amazon Bedrock, Google Cloud's Agent Platform, Microsoft Foundry and Claude Platform on AWS.

Troubleshooting distinguishes authentication failures, unreachable hosts, malformed responses, unsupported request fields, gateway context limits, missing model-picker entries, TLS trust differences and request-body filtering by an intermediate firewall.

Using it

Requirements

Manual setup requires Claude Code, a reachable gateway base URL and an organization-issued credential or command that retrieves one. The gateway team must identify any required custom headers or provider-specific routing. A corporate network may also require VPN access or a certificate-authority bundle trusted by Claude Code's runtime.

The page does not specify a universal minimum Claude Code version, a complete operating-system support matrix or infrastructure sizing. Some features and fixes have individual version requirements. Compatibility with a specific gateway product or upstream model remains unassessed.

Mechanism

For the standard route, ANTHROPIC_BASE_URL directs model requests to the gateway. ANTHROPIC_AUTH_TOKEN sends the credential in Authorization: Bearer, while ANTHROPIC_API_KEY sends it in x-api-key. A credential placed in the wrong variable may therefore reach the gateway in an unread header and produce a 401 response.

apiKeyHelper runs a shell command that prints only the current credential. Its value is sent in both authentication headers and cached for five minutes by default. CLAUDE_CODE_API_KEY_HELPER_TTL_MS changes that cache lifetime.

Settings-file env values override matching shell exports. ANTHROPIC_AUTH_TOKEN takes precedence over a saved claude.ai login immediately; ANTHROPIC_API_KEY requires one-time approval in interactive mode. Optional gateway model discovery uses CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1, although a replacing modelPicker configuration can hide discovered entries.

Provider-specific routes use their own base-URL variables and provider switches. Bedrock and Google Cloud's Agent Platform use native provider request formats; Foundry and Claude Platform on AWS use Anthropic Messages format. Authentication-skip settings prevent Claude Code from replacing gateway authentication with cloud-provider signing where documented.

Setup

First check whether configuration already exists. Start claude, open /status and inspect the Anthropic base URL and credential-source lines. The page then recommends sending a message: the displayed settings alone do not demonstrate a successful model response.

For manual setup, begin with shell exports for ANTHROPIC_BASE_URL and the appropriate credential variable, then perform the direct verification request. After verification, persist settings where the relevant process reads them. For CLI sessions and background agents, the guide recommends a settings-file env block when routing must apply consistently.

The global file is ~/.claude/settings.json. A manually created project-local .claude/settings.local.json should be ignored by Git before credentials are added; credentials should not go in the shared .claude/settings.json. In interactive sessions, project env settings apply only after the first-run wizard and folder trust, so initial authentication may require shell, global or managed settings.

VS Code needs claudeCode.environmentVariables in its own user settings because the extension checks credentials before launching its process. The desktop app instead uses third-party inference configuration, supplied by an administrator or entered through its developer configuration form.

GitHub Actions takes the gateway key through anthropic_api_key. For bearer-token gateways, the documented setup also supplies the same secret as ANTHROPIC_AUTH_TOKEN because the action's launch check does not read that variable. In the Agent SDK, TypeScript options.env replaces the inherited environment, so the example spreads process.env; Python ClaudeAgentOptions(env=...) merges with the inherited environment.

Example

For the page's illustrative standard-route setup, ANTHROPIC_BASE_URL points to [https://llm-gateway.example.com] and ANTHROPIC_AUTH_TOKEN contains an organization-issued bearer token. The hostname is a placeholder to replace with the actual gateway address.

The documented verification sends POST to [https://llm-gateway.example.com/v1/messages] with Authorization: Bearer, anthropic-version: 2023-06-01 and content-type: application/json. Its request uses model claude-sonnet-4-6, max_tokens of 1 and a user message containing a period. An x-api-key gateway needs the corresponding header and ANTHROPIC_API_KEY instead.

The page identifies a response with a msg_ identifier and content field as success. It treats an unknown-model error as evidence that the URL and credential worked, without establishing model availability. A real Claude Code message is still needed to check the application path. No example request or session was executed.

Assessment & evidence

Limitations

Cloud sessions and Claude Tag are outside the documented gateway deployment. Remote Control and voice dictation are unavailable while gateway credential variables or apiKeyHelper are active. Remote Control is also disabled when ANTHROPIC_BASE_URL points to a non-Anthropic host.

Routing model requests does not route all background traffic. CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 suppresses several external requests and disables automatic updates, but WebFetch's domain safety check still contacts [https://api.anthropic.com] unless separately skipped with skipWebFetchPreflight. Fast-mode availability checks have additional network and authentication constraints.

Gateway request validation and upstream capabilities can reject fields, tool schemas or adaptive thinking. CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 suppresses most prerelease fields, not every beta. The adaptive-thinking workaround documented for Opus 4.6 and Sonnet 4.6 is not presented as a universal fix for later models.

Gateway-specific context-limit errors can prevent automatic compaction. CLAUDE_CODE_AUTO_COMPACT_WINDOW is clamped to at least 100,000 tokens, so it cannot match a smaller gateway limit; manual /compact remains the documented recovery. Conflicting managed login requirements also require administrator action.

The desktop gateway configuration removes Anthropic-hosted cloud environments and Remote Control. Desktop SSH sessions are beta, require v1.40609.0 or later and an allowed-host configuration, and require the remote machine itself to reach the gateway.

Reasoning

The guide's diagnostic sequence separates different failure layers. A direct request checks the gateway address and credential, /status shows which configuration reached Claude Code, and an actual prompt exercises the application's request. This matters because a short verification request may pass while a real session is blocked by request-body inspection or unsupported fields.

Its configuration advice also follows process boundaries: shell exports reach programs launched from that shell, editor launch checks can happen before a child process reads settings, and background agents may source their environment differently. These distinctions explain why repeating the same terminal setup across every interface is insufficient.

A successful model response would establish that particular interaction, rather than complete network isolation or compatibility with every feature. Those broader properties remain unassessed.

Alternatives

Within the documented approach, administrator-distributed settings can remove the need for manual configuration. Fixed credentials can use environment variables, while expiring or vault-backed credentials can use apiKeyHelper. Provider-specific routes are appropriate when the gateway team explicitly names the corresponding provider.

A personal claude.ai login is a different authentication path mentioned by the page. Restoring voice dictation requires signing in with a Claude account and unsetting the gateway credential. Restoring Remote Control additionally requires unsetting ANTHROPIC_BASE_URL.

For different tasks, the page points administrators to [https://code.claude.com/docs/en/llm-gateway-rollout.md] and gateway implementers to [https://code.claude.com/docs/en/llm-gateway-protocol.md]. Their contents are outside the supplied evidence. No competing gateway products are compared.

Evidence

The evidence is the complete captured documentation page at [https://code.claude.com/docs/en/llm-gateway-connect.md], captured at 2026-11-25T17:18:14.568Z.

Behavioral claims come from that documentation. Linked pages and repositories were not included as evidence. No commands, HTTP requests, helpers, applications or SDK examples were executed, so there are no observed connection results or independent performance and security findings.

Access & freshness

Costs

The page supplies no gateway fees, Claude Code access prices, model token rates or infrastructure costs. Total cost and billing arrangements are unknown. The one-token verification example does not establish that verification or normal use is free.

Rights

The captured page contains no explicit license or redistribution grant for its prose or examples. Permission to redistribute the documentation or sample files is not established. Claude Code, gateway and model-provider usage terms are also not established by this page.

Freshness

The capture is dated 25 November 2026, but the page supplies no publication or last-updated date. Its version references describe particular compatibility boundaries and do not establish the latest available release.

The page states that helper output containing extra text fails on Claude Code v2.1.227 or later, and that disabling nonessential traffic also stopped discovery refresh before v2.1.257. Foundry bearer-token authentication requires v2.1.203 or later.

It also documents request-schema problems affecting gradual rollouts on v2.1.265 through v2.1.267, fixed in v2.1.268, and an advisor declaration problem on v2.1.275, addressed in v2.1.276. These notes make the installed client version relevant when diagnosing failures.

Actions

Obtain the gateway URL, credential type and any required headers from the gateway team. Confirm whether settings are already distributed, which interface will be used, and whether a provider-specific route is required.

Follow the documented direct verification request, inspect /status and send a real Claude Code prompt before persisting the configuration. Keep credentials out of shared project settings and use the interface-specific configuration described by the page.

For an organizational rollout, confirm available models, context and output limits, certificate requirements, allowed external connections and the update path if automatic updates are disabled. Establish costs and usage terms separately, and check whether the unavailable hosted, Remote Control or voice features matter to the intended work.

Evidence for this report

selected-page.txtselected · checked 2026-11-25