modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -120,7 +120,7 @@ ---|--- `x-claude-code-request-class`| What kind of request this is: `main` for a turn of the main conversation, `subagent` for a turn of a [subagent](</docs/en/sub-agents>), `workflow` for an agent running inside a workflow, `compaction` for the summarization request that compacts a conversation, or `auxiliary` for side requests such as session titles, classifiers, and summaries. Sent on every request `x-claude-code-agent-type`| The kind of subagent that issued the request: a built-in agent type name such as `Explore`, `Plan`, or `general-purpose`, or `custom` for a user-defined agent, `teammate` for an [agent team](</docs/en/agent-teams>) member running in the lead’s process, or `fork` for a [fork](</docs/en/sub-agents#fork-the-current-conversation>). Present only on a subagent’s own turns; a subagent’s compaction or side requests keep the agent ID but carry no type. A user-chosen agent name is never sent -`x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the context window approached capacity, `manual` for `/compact`, or `reactive` when the API rejected a request as too long. The value is also `auto` for [idle compaction](</docs/en/settings-reference#idlecompaction>) in an interactive terminal session. Absent on every other request, including one that writes a summary in the background before a compaction +`x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the conversation approached the [auto-compact window](</docs/en/model-config#context-window-and-auto-compaction>), `manual` for `/compact`, or `reactive` when the API rejected a request as too long. The value is also `auto` for [idle compaction](</docs/en/settings-reference#idlecompaction>) in an interactive terminal session. Absent on every other request, including one that writes a summary in the background before a compaction `x-claude-code-context-compacted`| Present once, on the first main-conversation request after a compaction, with the same values as `x-claude-code-compaction`. The conversation prefix before this request is no longer used, so a cache keyed on it can be dropped `x-claude-code-prev-tool-durations`| Measured run time of the tool calls whose results this request carries, as `<name>=<ms>;<name>=<ms>`, for example `Bash=742;Read=9`. Sent on the next request of the same conversation after a batch of tool calls, from the main session or a subagent `x-claude-code-prompt-id`| Random UUID that identifies the user prompt a request serves. Requests serving one prompt share the value, including the turns of subagents that prompt started. Requests not attributed to a prompt omit it. Use it to group a session’s requests by prompt. Requires Claude Code v2.1.283 or later @@ -153,8 +153,8 @@ Claude Code prepends a short attribution block to the system prompt containing the client version and a fingerprint derived from the conversation. The `api.anthropic.com` endpoint strips the block before processing when it arrives unchanged as the first system block, so it doesn’t affect first-party prompt caching. Any other upstream receives it as part of the prompt. The strip is positional, so it only works when the gateway forwards the `system` array unchanged. To keep the block out of the prompt without losing other system content: - * Forward the `system` array exactly as received, keeping the block first: prepending another system block, reordering the array, or converting it to a single string defeats the strip, and the block then reaches the model and the prompt cache key. - * Keep the block in its own array entry: the endpoint treats a merged block that starts with the attribution header as attribution in its entirety and drops everything merged into it, including the rest of the system prompt. + * Forward the `system` array exactly as received, keeping the block first. Prepending another system block or reordering the array defeats the strip, and the block then reaches the model and the prompt cache key. + * Keep the block in its own array entry, and don’t convert `system` to a single string. The endpoint treats a merged block that starts with the attribution header as attribution in its entirety and drops everything merged into it, including the rest of the system prompt. * If your gateway must reshape system content, set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) so Claude Code omits the block. Anthropic and the cloud providers’ Claude endpoints read the block for attribution, so omit it at the client rather than stripping or moving it in the gateway. The variable exists for gateway and third-party caching compatibility, not as a privacy control: on a direct connection the full request already goes to the Anthropic API either way. When both of these hold, Claude Code keeps the block on [auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) classifier requests even when you set the variable to `0`: @@ -194,7 +194,7 @@ When the upstream rejects one of these capabilities, Claude Code can retry the request on its own with the rejected part removed or changed: * When a `400` says the `thinking.type` value `enabled` or `adaptive` isn’t supported, Claude Code retries once with the other type and keeps the `thinking` field. Later requests to that model keep the switched type until Claude Code exits. Before v2.1.121, Claude Code didn’t retry, so [`thinking.type.enabled is not supported`](</docs/en/errors#thinking-type-enabled-is-not-supported-for-this-model>) reached the developer - * When the upstream rejects a `role: "system"` entry inside `messages`, Claude Code retries once without those mid-conversation system messages and carries their text in user messages instead. Later requests in the conversation keep that shape until the developer runs `/clear` or the conversation compacts + * When the upstream rejects a `role: "system"` entry inside the `messages` array, Claude Code moves the mid-conversation system text into user messages and retries once. After a successful retry, later requests in the conversation keep that text in user messages until the developer runs the `/clear` command or the conversation compacts * When the upstream rejects only the `cache_control` marker on a mid-conversation system message, Claude Code keeps the system messages and retries once with the marker moved. The marker goes on the last entry in `messages` that isn’t a system message, in that retry and in later requests until Claude Code exits * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), including with a `400` whose message says the block is `bound to a different conversation`, Claude Code removes earlier thinking blocks from the request, retries, and keeps them out of every later request. New responses still include thinking * When the gateway or its upstream rejects the [advisor tool](</docs/en/advisor>) entry in `tools` as an unrecognized tool type, Claude Code retries once without that entry and its `anthropic-beta` value. Later requests omit them. Claude Code recognizes this rejection by a `400` or `422` response whose message names the tool type after `Input tag`, such as `Input tag 'advisor_20260301'`. Before v2.1.280, Claude Code didn’t retry this rejection @@ -208,6 +208,23 @@ The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. Most of this retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. +#### Retry unchanged, then without earlier thinking + +If Claude Code doesn’t recognize the error body of your gateway’s `400` or `422`, it can retry a request that carried `thinking` or `redacted_thinking` blocks from earlier turns. Claude Code retries once in case the error was transient, and once to test whether your gateway rewrote the upstream’s error body for a rejected thinking signature. Look for the two retries in your gateway’s log: + + 1. The same body again + 2. The same body without those blocks, sent only if your gateway answers the first retry with another `400` or `422` that Claude Code doesn’t recognize + +Find your gateway’s response to the retries in the first column: + +Your gateway| What follows| What you do +---|---|--- +Accepts the first retry| Later requests still carry those blocks| Nothing +Rejects the first retry, then accepts the second| Later requests omit those blocks too| Nothing, unless your gateway rewrites the upstream’s error bodies. Then forward them unmodified, or put `capability_rejected: thinking_signature` in the rewritten message when the upstream rejects a thinking signature. Claude Code then recognizes the rejection and sends a single retry without the blocks. +Rejects both retries| Another retry of the same request can follow, such as the retry without tool search. If none does, the developer sees the original error, followed by `If other sessions work and this one keeps failing, start a new session`. Later requests carry those blocks again.| If your gateway rewrites the upstream’s error bodies, forward them unmodified, so that Claude Code can recognize the error. Otherwise, nothing. + +To disable both retries, for example because your gateway rejects requests itself under a content policy, have developers set [`CLAUDE_CODE_DISABLE_REPLAYED_THINKING_PROBE`](</docs/en/env-vars>) to `1`, which requires Claude Code v2.1.334 or later. With the retries disabled, a conversation that the second retry would have recovered keeps failing until the developer starts a new session. + #### Retry without a rejected beta value When a `400` rejects by name an `anthropic-beta` value that this retry covers, the gateway sees the request once more without it. Later requests omit the value. Most values it covers require v2.1.314 or later. Your gateway needs no change if the message of the `400` it returns carries the value in either of these forms:
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -1,4 +1,4 @@ -This page documents the requests Claude Code sends to a gateway, including the endpoints it calls, the headers and body fields the gateway must forward, and which features stop working when it doesn’t. It is written for operators configuring a gateway product to work with Claude Code. The [Claude apps gateway](</docs/en/claude-apps-gateway>), Anthropic’s self-hosted gateway, serves its own endpoint reference at `GET /protocol`, covering that gateway’s sign-in, inference, managed settings, model discovery, and telemetry endpoints. It is a separate document from this guide. +This page documents the requests Claude Code sends to a gateway, including the endpoints it calls, the headers and body fields the gateway must forward, and which features stop working when it doesn’t. It is written for operators configuring a gateway product to work with Claude Code. The [Claude apps gateway](</docs/en/claude-apps-gateway>), Anthropic’s self-hosted gateway, serves its own endpoint reference at `GET /protocol`, covering that gateway’s sign-in, inference, managed settings, model discovery, and telemetry endpoints. * To roll out an existing or third-party gateway for your organization, see [Roll out an LLM gateway](</docs/en/llm-gateway-rollout>) * If you’re an individual developer authenticating Claude Code to a gateway with a credential you were given, see [Connect Claude Code to an LLM gateway](</docs/en/llm-gateway-connect>)
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -88,7 +88,7 @@ Two client-side settings change what Claude Code assumes for a model ID it doesn’t recognize, whichever connection method the developer uses: - * **Context window** : Claude Code assumes a 1M token context window by default. To declare the real window, see [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) + * **Context window** : Claude Code assumes a 1M token context window by default since v2.1.323. To declare the real window, see [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) * **Capabilities** : to give a gateway alias the capabilities of the model behind it, map that model’s Anthropic ID to your alias with a [`modelOverrides`](</docs/en/errors#unrecognized-model-id-on-a-request>) entry in the settings you distribute. For where the `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` variables apply, see feature pass-through ## Request headers @@ -173,7 +173,7 @@ ### Beta header and body field pairs -Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces `400` errors. When both halves are absent together, the feature turns off quietly. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. +Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces `400` errors. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. Feature| Header and body pair| Symptom when broken| Remediation ---|---|---|---
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -88,7 +88,7 @@ Two client-side settings change what Claude Code assumes for a model ID it doesn’t recognize, whichever connection method the developer uses: - * **Context window** : Claude Code assumes 200K, or 1M when the ID carries `[1m]`. To declare the real window, see [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) + * **Context window** : Claude Code assumes a 1M token context window by default. To declare the real window, see [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) * **Capabilities** : to give a gateway alias the capabilities of the model behind it, map that model’s Anthropic ID to your alias with a [`modelOverrides`](</docs/en/errors#unrecognized-model-id-on-a-request>) entry in the settings you distribute. For where the `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` variables apply, see feature pass-through ## Request headers @@ -250,6 +250,7 @@ * The top-level `output_config.effort` field. Automatic retry and error forwarding covers an upstream that rejects it * The adaptive reasoning `thinking` field, which has no beta header * The `role: "system"` entries that carry mid-conversation system messages + * The `anthropic-beta` value and `safeguards` field for auto mode’s [server-side classifier review](</docs/en/permission-modes#server-side-classifier-review>), in sessions where that review stays on, such as when `/status` shows **Auto mode server** as `Enabled`. To turn the review off, set `CLAUDE_CODE_AUTO_MODE_SERVER=0` before starting the session. In the terminal, `/status` then shows **Auto mode server** as `Disabled`. * The OAuth `anthropic-beta` value that subscription authentication requires * Header values and body fields developers add themselves through [`ANTHROPIC_BETAS`](</docs/en/env-vars>) or [`CLAUDE_CODE_EXTRA_BODY`](</docs/en/env-vars>)
modified
Show diff (306 lines)
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -20,11 +20,7 @@ Anything not marked forward unchanged is yours to consume or ignore. -## - -​ - -API formats +## API formats A gateway must expose at least one of the following API formats to Claude Code clients. A client picks a format and points Claude Code at your gateway with the variables in the Selected by column of the table below. Google Cloud’s Agent Platform is Google Cloud’s Claude endpoint, formerly Vertex AI; its variable names keep the `VERTEX` spelling. @@ -34,19 +30,11 @@ Amazon Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`, `/model/{model}/count-tokens` (optional)| `anthropic_beta` and `anthropic_version` request body fields Google Cloud’s Agent Platform rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field -### - -​ - -Foundry and Claude Platform on AWS +### Foundry and Claude Platform on AWS Microsoft Foundry and the [Claude Platform on AWS](</docs/en/claude-platform-on-aws>) implement the Anthropic Messages format. Claude Code routes to them through their own variables, `ANTHROPIC_FOUNDRY_BASE_URL` and `ANTHROPIC_AWS_BASE_URL`, but a gateway fronting either implements the Anthropic Messages row above. A gateway fronting the Claude Platform on AWS must also forward the `anthropic-workspace-id` header, which [that platform requires on every request](</docs/en/claude-platform-on-aws>). -### - -​ - -Optional endpoints and startup traffic +### Optional endpoints and startup traffic Token-counting endpoints are the only optional ones: when they’re absent, Claude Code falls back to a character-based estimate of context usage. Match on the path, not the full URL: @@ -55,11 +43,7 @@ A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. Sessions that go through a gateway aren’t eligible for the HIPAA configuration. [Check how developers sign in and connect](</docs/en/hipaa-setup#check-how-developers-sign-in-and-connect>) lists which sign-in and connection methods are. See [The HIPAA configuration behind a gateway](</docs/en/llm-gateway-rollout#the-hipaa-configuration-behind-a-gateway>). The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. -### - -​ - -Streaming +### Streaming Claude Code reads each streaming inference response event by event as it arrives, so the way your gateway relays the stream affects what the user sees: @@ -69,11 +53,7 @@ * Claude Code aborts a streaming response once no bytes reach it for longer than its [streaming idle timeout](</docs/en/network-config#streaming-idle-watchdogs>). During a long thinking pause, the upstream’s SSE `ping` events can be the only bytes on the stream, so a gateway that strips or buffers them can trip that timeout partway through a response. A gateway that translates from an upstream without pings, such as Amazon Bedrock’s binary event stream, has the same gap unless it emits its own `ping` events. * On the Amazon Bedrock InvokeModel format, Claude Code reads the `/model/{model}/invoke-with-response-stream` response as the binary `application/vnd.amazon.eventstream` body Bedrock returns, and can’t parse it once a gateway converts it to server-sent events or rewrites that `Content-Type` header. [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>) describes what the user sees then. -### - -​ - -Format mismatch with the upstream +### Format mismatch with the upstream Which format the client speaks determines what your gateway receives. The common failure mode is a mismatch between the format the client sends to your gateway and the format the upstream provider behind it accepts. @@ -82,11 +62,7 @@ Bridging that difference is your gateway’s job. Feature pass-through describes what breaks when it doesn’t. If your upstream is Amazon Bedrock or Google Cloud’s Agent Platform, you can avoid the bridging by exposing that provider’s format instead. [Route to a cloud provider through a gateway](</docs/en/llm-gateway-connect#route-to-a-cloud-provider-through-a-gateway>) shows the client configuration for that format. -## - -​ - -How the connection method changes client behavior +## How the connection method changes client behavior The way a developer connects to your gateway determines which model IDs, `anthropic-beta` values, and request fields Claude Code sends, and which defaults it applies. Your gateway sees one of three client behaviors: @@ -94,11 +70,7 @@ * **Anthropic Messages format** : the developer sets `ANTHROPIC_BASE_URL` to your gateway. Claude Code treats the gateway as the Claude API and can’t tell which upstream you forward to. * **Claude apps gateway sign-in** : the developer signs in to a [Claude apps gateway](</docs/en/claude-apps-gateway>). That gateway speaks the Anthropic Messages format but can route to any upstream, so Claude Code sends only the `anthropic-beta` values and model-capability assumptions that Amazon Bedrock and Agent Platform also accept. -### - -​ - -Requests and defaults by connection method +### Requests and defaults by connection method The table below compares the three connection methods, one behavior per row. It leaves out Microsoft Foundry and Claude Platform on AWS, which also use the Anthropic Messages format but which Claude Code reaches through their own variables. For those, see the [Microsoft Foundry](</docs/en/microsoft-foundry>) and [Claude Platform on AWS](</docs/en/claude-platform-on-aws>) pages. @@ -112,22 +84,14 @@ For the features each connection supports and the telemetry it sends to Anthropic by default, see [Feature availability](</docs/en/feature-availability#availability-by-model-provider>) and [Default behaviors by API provider](</docs/en/data-usage#default-behaviors-by-api-provider>). -### - -​ - -Settings for unrecognized model IDs +### Settings for unrecognized model IDs Two client-side settings change what Claude Code assumes for a model ID it doesn’t recognize, whichever connection method the developer uses: * **Context window** : Claude Code assumes 200K, or 1M when the ID carries `[1m]`. To declare the real window, see [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) * **Capabilities** : to give a gateway alias the capabilities of the model behind it, map that model’s Anthropic ID to your alias with a [`modelOverrides`](</docs/en/errors#unrecognized-model-id-on-a-request>) entry in the settings you distribute. For where the `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` variables apply, see feature pass-through -## - -​ - -Request headers +## Request headers Claude Code includes these headers on API requests. Header names are case-insensitive on the wire. Forward `anthropic-version` and `anthropic-beta` unchanged, plus `anthropic-workspace-id` when the upstream is the [Claude Platform on AWS](</docs/en/claude-platform-on-aws>). Also forward `Authorization` when your gateway authenticates to Anthropic with the developer’s claude.ai login and not a key of its own. The rest the gateway may consume for routing, attribution, and tracing, and need not forward. @@ -142,11 +106,7 @@ Subagent IDs are generated fresh each time Claude Code spawns a subagent. Teammate agents, the named members of an [agent team](</docs/en/agent-teams>), reuse a stable name-based ID across reconnections. In both cases the ID identifies an agent, not a person or a device, so don’t treat the agent ID header as a user identifier. If your developers set `ANTHROPIC_CUSTOM_HEADERS`, those headers appear on requests as well. -### - -​ - -Gateway hint headers +### Gateway hint headers Claude Code can also send routing hints: per-request facts a gateway or router can use to schedule, cache, or attribute a request. Requires Claude Code v2.1.273 or later. Whether a request carries them depends on where Claude Code sends it: @@ -174,19 +134,11 @@ * Absence: compaction calls, side requests, and the first request of a new prompt never carry it. Don’t read a missing header as a turn that ran no tools * Times: each one excludes permission prompts and hooks, and parallel tool calls each report their own time, so the entries don’t add up to the gap between requests -### - -​ - -Forward as open lists +### Forward as open lists Treat the headers and body fields as open lists, not closed ones. Claude Code gains capabilities over releases, and they arrive as new `anthropic-beta` values, new request body fields, and occasionally new `anthropic-*` or `x-claude-code-*` headers. When forwarding to an Anthropic-format upstream, pass `anthropic-*` request headers and request body fields through unchanged rather than allowlisting the ones you see today. A gateway pinned to an observed list strips the next capability’s header or field and breaks it on the release that introduces it. The exception is a non-Anthropic upstream such as Amazon Bedrock or Google Cloud’s Agent Platform, where bridging the schema difference is the gateway’s job; see feature pass-through. -## - -​ - -Response headers +## Response headers Claude Code reads these response headers to detect stalled streams, to decide whether and when to retry, and to show usage limits. The table lists what to return for each. Also forward error response bodies unmodified, so Claude Code’s capability-rejection recovery can match the upstream’s error wording. @@ -197,11 +149,7 @@ `x-should-retry`| Pass the upstream’s value through unchanged. Claude Code reads this header as one input when deciding whether to retry a failed request: `true` marks the response retryable and `false` marks it not retryable. For retry counts, backoff, and which failures Claude Code retries, see [automatic retries](</docs/en/errors#automatic-retries>) `anthropic-ratelimit-unified-*`| Forward the upstream’s values unchanged on every response. Claude Code reads them on successful responses to show usage against plan limits to developers signed in with claude.ai, and on a `429` to tell a plan limit or spend cap from a temporary throttle; see [usage limits](</docs/en/errors#usage-limits>) -## - -​ - -System prompt attribution block +## System prompt attribution block Claude Code prepends a short attribution block to the system prompt containing the client version and a fingerprint derived from the conversation. The `api.anthropic.com` endpoint strips the block before processing when it arrives unchanged as the first system block, so it doesn’t affect first-party prompt caching. Any other upstream receives it as part of the prompt. The strip is positional, so it only works when the gateway forwards the `system` array unchanged. To keep the block out of the prompt without losing other system content: @@ -219,19 +167,11 @@ * Implements a prompt cache keyed on the request body. * Forwards requests to a third-party provider such as Amazon Bedrock, Microsoft Foundry, or Google Cloud’s Agent Platform, in the Anthropic Messages format or the provider’s own, where the changing prefix reduces prompt-cache reuse on that provider. -## - -​ - -Feature pass-through +## Feature pass-through Claude Code treats an `ANTHROPIC_BASE_URL` gateway as an Anthropic-format endpoint and sends it the beta headers and request body fields it sends to `api.anthropic.com`, except a small set of diagnostics and defaults reserved for direct connections, such as the fine-grained tool streaming default covered below. That set varies by release, so don’t depend on its contents. Fine-grained tool streaming is one of the direct-connection defaults: it is off by default whenever requests route through a custom base URL, and a gateway receives it when developers set [`CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING=1`](</docs/en/env-vars>). -### - -​ - -Beta header and body field pairs +### Beta header and body field pairs Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces `400` errors. When both halves are absent together, the feature turns off quietly. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. @@ -249,11 +189,7 @@ The `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` [variables](</docs/en/model-config>) declare model capabilities only in the provider configurations: `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY`, and [`CLAUDE_CODE_USE_MANTLE`](</docs/en/amazon-bedrock#use-the-mantle-endpoint>). They have no effect behind an `ANTHROPIC_BASE_URL` gateway. -### - -​ - -Automatic retry and error forwarding +### Automatic retry and error forwarding When the upstream rejects one of these capabilities, Claude Code can retry the request on its own with the rejected part removed or changed: @@ -272,11 +208,7 @@ The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. Most of this retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. -#### - -​ - -Retry without a rejected beta value +#### Retry without a rejected beta value When a `400` rejects by name an `anthropic-beta` value that this retry covers, the gateway sees the request once more without it. Later requests omit the value. Most values it covers require v2.1.314 or later. Your gateway needs no change if the message of the `400` it returns carries the value in either of these forms: @@ -289,11 +221,7 @@ * **A value Claude Code doesn’t recognize** : a value that a developer set through `ANTHROPIC_BETAS` stays on each request, so the developer’s requests keep failing with the `400`. Have the developer remove the entry * **A bare`invalid beta flag`**: Claude Code guesses which value the upstream rejected. If the request carried a value it guesses at, the gateway sees the request again without that value. If the `400` still reaches the developer, have your gateway name the rejected value in one of those forms -#### - -​ - -How long a rejected beta value stays out +#### How long a rejected beta value stays out Upstream rejected| Requests that omit it| Until ---|---|--- @@ -302,19 +230,11 @@ `context_management` or another `anthropic-beta` value the retry by name covers| Requests in the same conversation| The conversation ends or Claude Code rebuilds its prompt, such as when the main conversation compacts `context_management` or another value that retry covers, when the error message opens with the API’s own sentence for the rejection, such as `Unexpected value(s)`, or carries a `beta_header:` token| Also new conversations on the model the rejected request named, including after `/clear`| Claude Code exits -#### - -​ - -Retry without tool search +#### Retry without tool search On v2.1.305 or later, Claude Code resends a request without [`defer_loading` fields and `tool_reference` blocks](</docs/en/mcp#tool-search-through-a-gateway>) after a `400` or `422` that names tool search or whose cause it doesn’t recognize. After a successful retry, later requests in that conversation omit them too. The developer’s requests keep working without any change on the gateway, with their MCP tools loaded upfront. When Claude Code tries tool search again, the gateway can see another rejected request followed by its retry. For tool search itself, Claude Code expects the gateway to forward the `defer_loading` fields and `tool_reference` blocks with their `anthropic-beta` value. -### - -​ - -Disable pre-release capabilities +### Disable pre-release capabilities When your gateway or its upstream rejects pre-release `anthropic-beta` values or the body fields that pair with them, and you can’t forward both halves, have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`. With the variable set, Claude Code stops sending pre-release capabilities and the `anthropic-beta` values that pair with them, including: @@ -341,19 +261,11 @@ The set of capabilities Claude Code sends grows over releases. For current beta header strings, see the [beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>); test your gateway against new Claude Code releases rather than pinning to an observed list. -## - -​ - -Model discovery +## Model discovery When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. If you or your administrator set `replaceBuiltInOptions` in a [`modelPicker`](</docs/en/settings-reference#modelpicker>) lineup, Claude Code hides the discovered models from the picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key don’t surface every model the key can access to every user. -### - -​ - -When discovery runs +### When discovery runs Discovery applies only to the Anthropic Messages format. It doesn’t run when: @@ -362,11 +274,7 @@ Discovery still runs when [nonessential traffic is turned off](</docs/en/llm-gateway-connect#turn-off-traffic-outside-the-gateway-path>), because the request goes only to your gateway. Before v2.1.257, discovery didn’t run while nonessential traffic was turned off. -### - -​ - -Request and response +### Request and response The request is `GET /v1/models?limit=1000` with a timeout of 3 seconds by default, and any redirect is treated as failure so the credential can’t leak to a redirect target. A gateway that responds slower than the timeout, or one that redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. To give a slow gateway longer, set [`CLAUDE_CODE_GATEWAY_MODEL_DISCOVERY_TIMEOUT_MS`](</docs/en/env-vars#variables>). The variable requires Claude Code v2.1.269 or later. Claude Code sends the discovery request with both credential headers below and omits a header whose value doesn’t resolve. Sending both headers requires Claude Code v2.1.248 or later. Earlier versions send only `Authorization` when `ANTHROPIC_AUTH_TOKEN` is set and only `x-api-key` otherwise. @@ -388,11 +296,7 @@ Claude Code keeps an entry when its `id` contains `claude` or `anthropic` anywhere in the string, matched case-insensitively, and ignores the rest. Provider-prefixed IDs such as `vertex_ai/claude-sonnet-4-6` or `bedrock/anthropic.claude-sonnet-4-5` pass the filter; an ID that contains neither substring doesn’t. Before v2.1.223, Claude Code kept an entry only when its `id` began with `claude` or `anthropic`, which hid provider-prefixed IDs. -### - -​ - -Picker entries and caching +### Picker entries and caching The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry uses `display_name` as its name when the gateway sends one that differs from the `id`. Otherwise the entry shows the model’s name when Claude Code [recognizes the `id`](</docs/en/model-config#customize-pinned-model-display-and-capabilities>), and the `id` when it doesn’t. For example, an entry with the `id` `my-gateway-claude-sonnet-4-6` and no `display_name` appears as `Sonnet 4.6`. Discovery adds only models that the [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) allows. Each entry also shows the model’s `description`, collapsed to one line. An entry without a `description` reads “From gateway” instead. Before v2.1.257, every discovered entry read “From gateway”. A discovered ID doesn’t get its own row when it matches a row already in the picker: @@ -401,11 +305,7 @@ Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. -## - -​ - -Related resources +## Related resources For the rest of the gateway documentation set and the underlying API references:
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -30,7 +30,7 @@ Format| Selected by| Endpoints| Forward unchanged ---|---|---|--- -Anthropic Messages| `ANTHROPIC_BASE_URL`| `/v1/messages`, `/v1/messages/count_tokens` (optional)| `anthropic-beta` and `anthropic-version` request headers +Anthropic Messages| `ANTHROPIC_BASE_URL`| `/v1/messages`, `/v1/messages/count_tokens` (optional)| `anthropic-beta` and `anthropic-version` request headers, plus `Authorization` when a claude.ai login authenticates the request to Anthropic Amazon Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`, `/model/{model}/count-tokens` (optional)| `anthropic_beta` and `anthropic_version` request body fields Google Cloud’s Agent Platform rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field @@ -129,11 +129,11 @@ Request headers -Claude Code includes these headers on API requests. Header names are case-insensitive on the wire. Forward `anthropic-version` and `anthropic-beta` unchanged, plus `anthropic-workspace-id` when the upstream is the [Claude Platform on AWS](</docs/en/claude-platform-on-aws>); the rest the gateway may consume for routing, attribution, and tracing, and need not forward. +Claude Code includes these headers on API requests. Header names are case-insensitive on the wire. Forward `anthropic-version` and `anthropic-beta` unchanged, plus `anthropic-workspace-id` when the upstream is the [Claude Platform on AWS](</docs/en/claude-platform-on-aws>). Also forward `Authorization` when your gateway authenticates to Anthropic with the developer’s claude.ai login and not a key of its own. The rest the gateway may consume for routing, attribution, and tracing, and need not forward. Header| Description ---|--- -`Authorization`, `x-api-key`| The developer’s gateway credential, in one or both headers depending on which [credential variable](</docs/en/llm-gateway-connect#set-the-credential-variable>) they set +`Authorization`, `x-api-key`| The developer’s gateway credential, in one or both headers depending on which [credential variable](</docs/en/llm-gateway-connect#set-the-credential-variable>) they set. With a claude.ai login and no gateway credential, `Authorization` carries the login’s token `anthropic-version`| API version, currently `2023-06-01`. Amazon Bedrock- and Google Cloud’s Agent Platform-format requests also carry the `anthropic_version` body field, whose value is the provider dialect string, not this header’s value `anthropic-beta`| Comma-separated capability values for the request. Forward the header verbatim; don’t allowlist individual values, because the set changes with Claude Code releases. When the developer authenticates with a claude.ai login, which is possible when `ANTHROPIC_BASE_URL` is set without a gateway credential variable, this header also carries an OAuth capability that the upstream requires, and stripping it fails those requests with `401` `x-claude-code-session-id`| A unique identifier for the current Claude Code session. Use it to aggregate all requests from one session without parsing request bodies
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -243,7 +243,7 @@ Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header. For `defer_loading`, see Retry without tool search| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`, which removes the format and task budget settings but not effort. To remove only the format, they can set [`CLAUDE_CODE_DISABLE_STRUCTURED_OUTPUTS=1`](</docs/en/env-vars>) instead, which requires v2.1.288 or later Mid-conversation system messages| No beta header. Claude Code sends some reminder and attachment text as `role: "system"` entries in `messages` for Claude Opus 4.8, models released after it, and unrecognized model IDs| `400` such as `Unexpected role "system"`| Claude Code retries without system messages. To stop system messages on an alias of a model released before Claude Opus 4.8, add a `modelOverrides` entry to the settings you distribute -[Effort set per turn](</docs/en/prompt-caching#changing-effort-level>)| On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1, a beta header pairs with `output_config.effort` on `role: "system"` entries, either a system message or an entry with empty content| `400` with `messages.N: system content must contain at least one block` when your gateway strips the field from an empty entry| Forward both, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` to stop the field and the empty entries +[Effort set per turn](</docs/en/prompt-caching#changing-effort-level>)| On Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.2, and Fable 5.1, a beta header pairs with `output_config.effort` on `role: "system"` entries. An entry is a system message or one with empty content| `400` with `messages.N: system content must contain at least one block` when your gateway strips the field from an empty entry| Forward both, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` to stop the field and the empty entries [Prompt caching](</docs/en/prompt-caching>)| No beta pairing. Claude Code attaches `cache_control` markers to `system` blocks and to `messages` entries, including `role: "system"` entries appended mid-conversation| No error: the conversation bills as uncached input on every turn, visible as high `input_tokens` with little or no cache activity in `usage`| Forward `cache_control` unchanged wherever it appears, and don’t convert block-form `system` or message content to plain strings [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| No error: Claude Code falls back to a character-based estimate, so `/context` shows approximate counts| Expose the endpoint for exact token counts
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -261,12 +261,13 @@ * When the upstream rejects a `role: "system"` entry inside `messages`, Claude Code retries once without those mid-conversation system messages and carries their text in user messages instead. Later requests in the conversation keep that shape until the developer runs `/clear` or the conversation compacts * When the upstream rejects only the `cache_control` marker on a mid-conversation system message, Claude Code keeps the system messages and retries once with the marker moved. The marker goes on the last entry in `messages` that isn’t a system message, in that retry and in later requests until Claude Code exits * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), including with a `400` whose message says the block is `bound to a different conversation`, Claude Code removes earlier thinking blocks from the request, retries, and keeps them out of every later request. New responses still include thinking - * When the gateway or its upstream rejects the [advisor tool](</docs/en/advisor>) entry in `tools` as an unrecognized tool type, Claude Code retries the request once without that entry and its `anthropic-beta` value. Later requests to that base URL leave the advisor out until Claude Code exits, and `/advisor` is unavailable to the developer for that time. Claude Code recognizes this rejection by a `400` or `422` response whose message names the tool type after `Input tag`, such as `Input tag 'advisor_20260301'`. Before v2.1.280, Claude Code didn’t retry this rejection - * When the upstream rejects `output_config.effort` or its `anthropic-beta` value, Claude Code retries and adds neither to requests for that model until Claude Code exits. Your gateway needs no change if it forwards the upstream’s `400` unmodified and the message: + * When the gateway or its upstream rejects the [advisor tool](</docs/en/advisor>) entry in `tools` as an unrecognized tool type, Claude Code retries once without that entry and its `anthropic-beta` value. Later requests omit them. Claude Code recognizes this rejection by a `400` or `422` response whose message names the tool type after `Input tag`, such as `Input tag 'advisor_20260301'`. Before v2.1.280, Claude Code didn’t retry this rejection + * When the upstream rejects `output_config.effort` or its `anthropic-beta` value, the gateway sees the request once more without them. Later requests omit them. Your gateway needs no change if it forwards the upstream’s `400` unmodified and the message: * Names `output_config.effort` alongside `Extra inputs are not permitted` * Says the model doesn’t support the effort parameter * Starts with `Unexpected value(s)` and lists `effort-2025-11-24` for the `anthropic-beta` header. Requires v2.1.310 or later. Developers whose [`ANTHROPIC_BETAS`](</docs/en/env-vars>) lists the value keep sending it and getting the `400`, so have them remove that entry - * When the upstream rejects the `context_management` field or its `anthropic-beta` value, the gateway sees the request once more without them. If the gateway sees them again in a later request and the upstream rejects them again, the same retry follows. Claude Code recognizes this rejection by its message, for example one containing `context_management: Extra inputs are not permitted`. Before v2.1.304, Claude Code didn’t retry this rejection + * When the upstream rejects the `context_management` field or its `anthropic-beta` value, the gateway sees the request once more without them. Later requests omit them. Claude Code recognizes this rejection by its message, for example one containing `context_management: Extra inputs are not permitted`. Before v2.1.304, Claude Code didn’t retry this rejection + * When a `400` rejects another `anthropic-beta` value by name, the gateway sees the request once more without it if the retry covers that value * When the upstream rejects a beta tool field other than `defer_loading`, such as `strict`, the `400` reaches the developer. Before it does, the gateway can see the request again without the tool search fields. To stop sending such fields, have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. Most of this retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. @@ -275,9 +276,39 @@ ​ +Retry without a rejected beta value + +When a `400` rejects by name an `anthropic-beta` value that this retry covers, the gateway sees the request once more without it. Later requests omit the value. Most values it covers require v2.1.314 or later. Your gateway needs no change if the message of the `400` it returns carries the value in either of these forms: + + * **The API’s sentence** : the `Unexpected value(s)` sentence that lists the value for the `anthropic-beta` header + * **A`beta_header:` token**: `capability_rejected: beta_header:` followed by the value, a `capability_rejected:` token + +The retry doesn’t cover cases such as a value with its own retry, a value Claude Code doesn’t recognize, or a message that names no value: + + * **A value with its own retry, such as advisor or tool search** : the gateway sees that capability’s own retry instead + * **A value Claude Code doesn’t recognize** : a value that a developer set through `ANTHROPIC_BETAS` stays on each request, so the developer’s requests keep failing with the `400`. Have the developer remove the entry + * **A bare`invalid beta flag`**: Claude Code guesses which value the upstream rejected. If the request carried a value it guesses at, the gateway sees the request again without that value. If the `400` still reaches the developer, have your gateway name the rejected value in one of those forms + +#### + +​ + +How long a rejected beta value stays out + +Upstream rejected| Requests that omit it| Until +---|---|--- +The advisor tool type, or the advisor’s `anthropic-beta` value| Requests to the same base URL. `/advisor` is unavailable| Claude Code exits +`output_config.effort` or its `anthropic-beta` value| Requests for the same model| Claude Code exits +`context_management` or another `anthropic-beta` value the retry by name covers| Requests in the same conversation| The conversation ends or Claude Code rebuilds its prompt, such as when the main conversation compacts +`context_management` or another value that retry covers, when the error message opens with the API’s own sentence for the rejection, such as `Unexpected value(s)`, or carries a `beta_header:` token| Also new conversations on the model the rejected request named, including after `/clear`| Claude Code exits + +#### + +​ + Retry without tool search -On v2.1.305 or later, a request carrying [`defer_loading` fields and `tool_reference` blocks](</docs/en/mcp#tool-search-through-a-gateway>) can arrive again without them after a `400` or `422` whose cause Claude Code doesn’t recognize. After a successful retry, later requests omit them too. The developer’s requests keep working without any change on the gateway, with their MCP tools loaded upfront. Claude Code tries tool search again later, so the gateway can see another rejected request followed by its retry. To keep the fields out of every request, have developers set `ENABLE_TOOL_SEARCH=false`. For tool search itself, Claude Code expects the gateway to forward the `defer_loading` fields and `tool_reference` blocks with their `anthropic-beta` value. +On v2.1.305 or later, Claude Code resends a request without [`defer_loading` fields and `tool_reference` blocks](</docs/en/mcp#tool-search-through-a-gateway>) after a `400` or `422` that names tool search or whose cause it doesn’t recognize. After a successful retry, later requests in that conversation omit them too. The developer’s requests keep working without any change on the gateway, with their MCP tools loaded upfront. When Claude Code tries tool search again, the gateway can see another rejected request followed by its retry. For tool search itself, Claude Code expects the gateway to forward the `defer_loading` fields and `tool_reference` blocks with their `anthropic-beta` value. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -160,7 +160,7 @@ ---|--- `x-claude-code-request-class`| What kind of request this is: `main` for a turn of the main conversation, `subagent` for a turn of a [subagent](</docs/en/sub-agents>), `workflow` for an agent running inside a workflow, `compaction` for the summarization request that compacts a conversation, or `auxiliary` for side requests such as session titles, classifiers, and summaries. Sent on every request `x-claude-code-agent-type`| The kind of subagent that issued the request: a built-in agent type name such as `Explore`, `Plan`, or `general-purpose`, or `custom` for a user-defined agent, `teammate` for an [agent team](</docs/en/agent-teams>) member running in the lead’s process, or `fork` for a [fork](</docs/en/sub-agents#fork-the-current-conversation>). Present only on a subagent’s own turns; a subagent’s compaction or side requests keep the agent ID but carry no type. A user-chosen agent name is never sent -`x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the context window approached capacity, `manual` for `/compact`, or `reactive` when the API rejected a request as too long. The value is also `auto` for [idle compaction](</docs/en/settings-reference#idlecompaction>). Absent on every other request +`x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the context window approached capacity, `manual` for `/compact`, or `reactive` when the API rejected a request as too long. The value is also `auto` for [idle compaction](</docs/en/settings-reference#idlecompaction>) in an interactive terminal session. Absent on every other request, including one that writes a summary in the background before a compaction `x-claude-code-context-compacted`| Present once, on the first main-conversation request after a compaction, with the same values as `x-claude-code-compaction`. The conversation prefix before this request is no longer used, so a cache keyed on it can be dropped `x-claude-code-prev-tool-durations`| Measured run time of the tool calls whose results this request carries, as `<name>=<ms>;<name>=<ms>`, for example `Bash=742;Read=9`. Sent on the next request of the same conversation after a batch of tool calls, from the main session or a subagent `x-claude-code-prompt-id`| Random UUID that identifies the user prompt a request serves. Requests serving one prompt share the value, including the turns of subagents that prompt started. Requests not attributed to a prompt omit it. Use it to group a session’s requests by prompt. Requires Claude Code v2.1.283 or later @@ -262,7 +262,10 @@ * When the upstream rejects only the `cache_control` marker on a mid-conversation system message, Claude Code keeps the system messages and retries once with the marker moved. The marker goes on the last entry in `messages` that isn’t a system message, in that retry and in later requests until Claude Code exits * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), including with a `400` whose message says the block is `bound to a different conversation`, Claude Code removes earlier thinking blocks from the request, retries, and keeps them out of every later request. New responses still include thinking * When the gateway or its upstream rejects the [advisor tool](</docs/en/advisor>) entry in `tools` as an unrecognized tool type, Claude Code retries the request once without that entry and its `anthropic-beta` value. Later requests to that base URL leave the advisor out until Claude Code exits, and `/advisor` is unavailable to the developer for that time. Claude Code recognizes this rejection by a `400` or `422` response whose message names the tool type after `Input tag`, such as `Input tag 'advisor_20260301'`. Before v2.1.280, Claude Code didn’t retry this rejection - * When the upstream rejects `output_config.effort`, Claude Code retries the request without effort and leaves it out of later requests to that model until Claude Code exits. Claude Code recognizes this rejection by a `400` whose message names `output_config.effort` together with `Extra inputs are not permitted`, or says the model doesn’t support the effort parameter + * When the upstream rejects `output_config.effort` or its `anthropic-beta` value, Claude Code retries and adds neither to requests for that model until Claude Code exits. Your gateway needs no change if it forwards the upstream’s `400` unmodified and the message: + * Names `output_config.effort` alongside `Extra inputs are not permitted` + * Says the model doesn’t support the effort parameter + * Starts with `Unexpected value(s)` and lists `effort-2025-11-24` for the `anthropic-beta` header. Requires v2.1.310 or later. Developers whose [`ANTHROPIC_BETAS`](</docs/en/env-vars>) lists the value keep sending it and getting the `400`, so have them remove that entry * When the upstream rejects the `context_management` field or its `anthropic-beta` value, the gateway sees the request once more without them. If the gateway sees them again in a later request and the upstream rejects them again, the same retry follows. Claude Code recognizes this rejection by its message, for example one containing `context_management: Extra inputs are not permitted`. Before v2.1.304, Claude Code didn’t retry this rejection * When the upstream rejects a beta tool field other than `defer_loading`, such as `strict`, the `400` reaches the developer. Before it does, the gateway can see the request again without the tool search fields. To stop sending such fields, have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -107,7 +107,7 @@ Model IDs in requests by default| The provider’s form, such as `us.anthropic.claude-opus-4-8` on Amazon Bedrock| Anthropic IDs, such as `claude-opus-4-8`| Anthropic IDs `anthropic-beta` values sent| The subset Amazon Bedrock and Agent Platform accept| The full set described under feature pass-through, unless the developer sets `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`| The subset Amazon Bedrock and Agent Platform accept Request fields for a model ID Claude Code doesn’t recognize, such as a gateway alias| Thinking with a fixed budget rather than adaptive reasoning, and no effort or context management fields. Claude Code still sends mid-conversation system messages| Everything current Claude models accept on the Claude API, including adaptive reasoning, effort, and context management, which an Amazon Bedrock or Agent Platform upstream can reject| Same as the Amazon Bedrock or Agent Platform format -One-hour [prompt cache TTL](</docs/en/prompt-caching#choose-the-ttl-yourself>) when a developer opts in| Requested through the `ttl` field in `cache_control`, with no beta value| Requested through the `ttl` field plus an `extended-cache-ttl` value in `anthropic-beta`, which you must forward| See the Claude apps gateway [availability and limitations](</docs/en/claude-apps-gateway#availability-and-limitations>) table +One-hour [prompt cache TTL](</docs/en/prompt-caching#choose-the-ttl-yourself>) when a developer opts in| Requested through the `ttl` field in `cache_control`, with no beta value| Requested through the `ttl` field plus an `extended-cache-ttl` value in `anthropic-beta`, which you must forward| Requested through the `ttl` field, with no beta value. See [One-hour prompt cache](</docs/en/claude-apps-gateway-config#one-hour-prompt-cache>) Model for [background tasks](</docs/en/costs#background-token-usage>) unless `ANTHROPIC_DEFAULT_HAIKU_MODEL` pins one| The default Sonnet model, or the main model once one is selected, as the [Amazon Bedrock](</docs/en/amazon-bedrock#4-pin-model-versions>) and [Agent Platform](</docs/en/google-vertex-ai#5-pin-model-versions>) pages describe| The main model, or the default Haiku model when `ANTHROPIC_API_KEY` or `apiKeyHelper` supplies an Anthropic Console key and `ANTHROPIC_AUTH_TOKEN` is unset| The main model For the features each connection supports and the telemetry it sends to Anthropic by default, see [Feature availability](</docs/en/feature-availability#availability-by-model-provider>) and [Default behaviors by API provider](</docs/en/data-usage#default-behaviors-by-api-provider>).
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -106,7 +106,7 @@ ---|---|---|--- Model IDs in requests by default| The provider’s form, such as `us.anthropic.claude-opus-4-8` on Amazon Bedrock| Anthropic IDs, such as `claude-opus-4-8`| Anthropic IDs `anthropic-beta` values sent| The subset Amazon Bedrock and Agent Platform accept| The full set described under feature pass-through, unless the developer sets `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`| The subset Amazon Bedrock and Agent Platform accept -Request fields for a model ID Claude Code doesn’t recognize, such as a gateway alias| Thinking with a fixed budget rather than adaptive reasoning, and no effort or context management fields| Everything current Claude models accept on the Claude API, including adaptive reasoning, effort, and context management, which an Amazon Bedrock or Agent Platform upstream can reject| Same as the Amazon Bedrock or Agent Platform format +Request fields for a model ID Claude Code doesn’t recognize, such as a gateway alias| Thinking with a fixed budget rather than adaptive reasoning, and no effort or context management fields. Claude Code still sends mid-conversation system messages| Everything current Claude models accept on the Claude API, including adaptive reasoning, effort, and context management, which an Amazon Bedrock or Agent Platform upstream can reject| Same as the Amazon Bedrock or Agent Platform format One-hour [prompt cache TTL](</docs/en/prompt-caching#choose-the-ttl-yourself>) when a developer opts in| Requested through the `ttl` field in `cache_control`, with no beta value| Requested through the `ttl` field plus an `extended-cache-ttl` value in `anthropic-beta`, which you must forward| See the Claude apps gateway [availability and limitations](</docs/en/claude-apps-gateway#availability-and-limitations>) table Model for [background tasks](</docs/en/costs#background-token-usage>) unless `ANTHROPIC_DEFAULT_HAIKU_MODEL` pins one| The default Sonnet model, or the main model once one is selected, as the [Amazon Bedrock](</docs/en/amazon-bedrock#4-pin-model-versions>) and [Agent Platform](</docs/en/google-vertex-ai#5-pin-model-versions>) pages describe| The main model, or the default Haiku model when `ANTHROPIC_API_KEY` or `apiKeyHelper` supplies an Anthropic Console key and `ANTHROPIC_AUTH_TOKEN` is unset| The main model @@ -225,15 +225,25 @@ Feature pass-through -Claude Code treats an `ANTHROPIC_BASE_URL` gateway as an Anthropic-format endpoint and sends it the beta headers and request body fields it sends to `api.anthropic.com`, except a small set of diagnostics and defaults reserved for direct connections, such as the fine-grained tool streaming default covered below. That set varies by release, so don’t depend on its contents. Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces hard `400` errors; only when both halves are absent together does the feature turn off quietly. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. Fine-grained tool streaming is one of the direct-connection defaults: it is off by default whenever requests route through a custom base URL, and a gateway receives it when developers set [`CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING=1`](</docs/en/env-vars>). +Claude Code treats an `ANTHROPIC_BASE_URL` gateway as an Anthropic-format endpoint and sends it the beta headers and request body fields it sends to `api.anthropic.com`, except a small set of diagnostics and defaults reserved for direct connections, such as the fine-grained tool streaming default covered below. That set varies by release, so don’t depend on its contents. Fine-grained tool streaming is one of the direct-connection defaults: it is off by default whenever requests route through a custom base URL, and a gateway receives it when developers set [`CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING=1`](</docs/en/env-vars>). + +### + +​ + +Beta header and body field pairs + +Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces `400` errors. When both halves are absent together, the feature turns off quietly. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. Feature| Header and body pair| Symptom when broken| Remediation ---|---|---|--- [Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude Opus 4.6, Claude Sonnet 4.6, Claude Haiku 5.5, Claude Fable 5, and later models, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead -[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-editing>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` +[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-editing>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock. On v2.1.304 or later, Claude Code retries on its own without the pair| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim -Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` +Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header. For `defer_loading`, see Retry without tool search| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`, which removes the format and task budget settings but not effort. To remove only the format, they can set [`CLAUDE_CODE_DISABLE_STRUCTURED_OUTPUTS=1`](</docs/en/env-vars>) instead, which requires v2.1.288 or later +Mid-conversation system messages| No beta header. Claude Code sends some reminder and attachment text as `role: "system"` entries in `messages` for Claude Opus 4.8, models released after it, and unrecognized model IDs| `400` such as `Unexpected role "system"`| Claude Code retries without system messages. To stop system messages on an alias of a model released before Claude Opus 4.8, add a `modelOverrides` entry to the settings you distribute +[Effort set per turn](</docs/en/prompt-caching#changing-effort-level>)| On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1, a beta header pairs with `output_config.effort` on `role: "system"` entries, either a system message or an entry with empty content| `400` with `messages.N: system content must contain at least one block` when your gateway strips the field from an empty entry| Forward both, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` to stop the field and the empty entries [Prompt caching](</docs/en/prompt-caching>)| No beta pairing. Claude Code attaches `cache_control` markers to `system` blocks and to `messages` entries, including `role: "system"` entries appended mid-conversation| No error: the conversation bills as uncached input on every turn, visible as high `input_tokens` with little or no cache activity in `usage`| Forward `cache_control` unchanged wherever it appears, and don’t convert block-form `system` or message content to plain strings [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| No error: Claude Code falls back to a character-based estimate, so `/context` shows approximate counts| Expose the endpoint for exact token counts @@ -245,15 +255,26 @@ Automatic retry and error forwarding -What Claude Code does after an upstream rejection depends on what was rejected: - - * When the upstream rejects the `thinking` field, a mid-conversation system message, or the `cache_control` marker on such a message, Claude Code retries the request and disables the rejected capability for the rest of the conversation +When the upstream rejects one of these capabilities, Claude Code can retry the request on its own with the rejected part removed or changed: + + * When a `400` says the `thinking.type` value `enabled` or `adaptive` isn’t supported, Claude Code retries once with the other type and keeps the `thinking` field. Later requests to that model keep the switched type until Claude Code exits. Before v2.1.121, Claude Code didn’t retry, so [`thinking.type.enabled is not supported`](</docs/en/errors#thinking-type-enabled-is-not-supported-for-this-model>) reached the developer + * When the upstream rejects a `role: "system"` entry inside `messages`, Claude Code retries once without those mid-conversation system messages and carries their text in user messages instead. Later requests in the conversation keep that shape until the developer runs `/clear` or the conversation compacts + * When the upstream rejects only the `cache_control` marker on a mid-conversation system message, Claude Code keeps the system messages and retries once with the marker moved. The marker goes on the last entry in `messages` that isn’t a system message, in that retry and in later requests until Claude Code exits * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), including with a `400` whose message says the block is `bound to a different conversation`, Claude Code removes earlier thinking blocks from the request, retries, and keeps them out of every later request. New responses still include thinking * When the gateway or its upstream rejects the [advisor tool](</docs/en/advisor>) entry in `tools` as an unrecognized tool type, Claude Code retries the request once without that entry and its `anthropic-beta` value. Later requests to that base URL leave the advisor out until Claude Code exits, and `/advisor` is unavailable to the developer for that time. Claude Code recognizes this rejection by a `400` or `422` response whose message names the tool type after `Input tag`, such as `Input tag 'advisor_20260301'`. Before v2.1.280, Claude Code didn’t retry this rejection * When the upstream rejects `output_config.effort`, Claude Code retries the request without effort and leaves it out of later requests to that model until Claude Code exits. Claude Code recognizes this rejection by a `400` whose message names `output_config.effort` together with `Extra inputs are not permitted`, or says the model doesn’t support the effort parameter - * Claude Code doesn’t retry rejections of context management or tool schema fields, so those `400` errors reach the developer - -The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. + * When the upstream rejects the `context_management` field or its `anthropic-beta` value, the gateway sees the request once more without them. If the gateway sees them again in a later request and the upstream rejects them again, the same retry follows. Claude Code recognizes this rejection by its message, for example one containing `context_management: Extra inputs are not permitted`. Before v2.1.304, Claude Code didn’t retry this rejection + * When the upstream rejects a beta tool field other than `defer_loading`, such as `strict`, the `400` reaches the developer. Before it does, the gateway can see the request again without the tool search fields. To stop sending such fields, have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` + +The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. Most of this retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. + +#### + +​ + +Retry without tool search + +On v2.1.305 or later, a request carrying [`defer_loading` fields and `tool_reference` blocks](</docs/en/mcp#tool-search-through-a-gateway>) can arrive again without them after a `400` or `422` whose cause Claude Code doesn’t recognize. After a successful retry, later requests omit them too. The developer’s requests keep working without any change on the gateway, with their MCP tools loaded upfront. Claude Code tries tool search again later, so the gateway can see another rejected request followed by its retry. To keep the fields out of every request, have developers set `ENABLE_TOOL_SEARCH=false`. For tool search itself, Claude Code expects the gateway to forward the `defer_loading` fields and `tool_reference` blocks with their `anthropic-beta` value. ### @@ -272,8 +293,9 @@ The variable doesn’t strip every `anthropic-beta` value. What it leaves in place includes: * The `anthropic-beta` values for extended context, interleaved thinking, and effort, which cloud providers also accept - * The `output_config.effort` field. Automatic retry and error forwarding covers an upstream that rejects it + * The top-level `output_config.effort` field. Automatic retry and error forwarding covers an upstream that rejects it * The adaptive reasoning `thinking` field, which has no beta header + * The `role: "system"` entries that carry mid-conversation system messages * The OAuth `anthropic-beta` value that subscription authentication requires * Header values and body fields developers add themselves through [`ANTHROPIC_BETAS`](</docs/en/env-vars>) or [`CLAUDE_CODE_EXTRA_BODY`](</docs/en/env-vars>)
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -160,7 +160,7 @@ ---|--- `x-claude-code-request-class`| What kind of request this is: `main` for a turn of the main conversation, `subagent` for a turn of a [subagent](</docs/en/sub-agents>), `workflow` for an agent running inside a workflow, `compaction` for the summarization request that compacts a conversation, or `auxiliary` for side requests such as session titles, classifiers, and summaries. Sent on every request `x-claude-code-agent-type`| The kind of subagent that issued the request: a built-in agent type name such as `Explore`, `Plan`, or `general-purpose`, or `custom` for a user-defined agent, `teammate` for an [agent team](</docs/en/agent-teams>) member running in the lead’s process, or `fork` for a [fork](</docs/en/sub-agents#fork-the-current-conversation>). Present only on a subagent’s own turns; a subagent’s compaction or side requests keep the agent ID but carry no type. A user-chosen agent name is never sent -`x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the context window approached capacity, `manual` for `/compact`, or `reactive` when the API rejected a request as too long. Absent on every other request +`x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the context window approached capacity, `manual` for `/compact`, or `reactive` when the API rejected a request as too long. The value is also `auto` for [idle compaction](</docs/en/settings-reference#idlecompaction>). Absent on every other request `x-claude-code-context-compacted`| Present once, on the first main-conversation request after a compaction, with the same values as `x-claude-code-compaction`. The conversation prefix before this request is no longer used, so a cache keyed on it can be dropped `x-claude-code-prev-tool-durations`| Measured run time of the tool calls whose results this request carries, as `<name>=<ms>;<name>=<ms>`, for example `Bash=742;Read=9`. Sent on the next request of the same conversation after a batch of tool calls, from the main session or a subagent `x-claude-code-prompt-id`| Random UUID that identifies the user prompt a request serves. Requests serving one prompt share the value, including the turns of subagents that prompt started. Requests not attributed to a prompt omit it. Use it to group a session’s requests by prompt. Requires Claude Code v2.1.283 or later @@ -279,8 +279,9 @@ When a host platform that embeds Claude Code sets [`CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`](</docs/en/env-vars>), `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` doesn’t stop auto mode sessions on Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or a [Claude apps gateway](</docs/en/claude-apps-gateway>) from asking the server for [classifier review](</docs/en/permission-modes#server-side-classifier-review>). That review adds an `anthropic-beta` value and a `safeguards` request field. Set `CLAUDE_CODE_AUTO_MODE_SERVER=0` to stop it there. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/managed-settings>). What Claude Code sends with that override in place depends on how you connect: - * On a direct connection, or through a gateway set with `ANTHROPIC_BASE_URL`, Claude Code keeps sending the tool-search beta header, `defer_loading` tool fields, and `tool_reference` blocks, and strips the rest + * On a direct connection without the HIPAA configuration, or through a gateway set with `ANTHROPIC_BASE_URL`, Claude Code keeps sending the tool-search beta header, `defer_loading` tool fields, and `tool_reference` blocks * On a cloud provider, or signed in through a [Claude apps gateway](</docs/en/claude-apps-gateway>), the override has no effect + * In a session that [gets the HIPAA configuration](</docs/en/hipaa-setup#check-how-developers-sign-in-and-connect>), the override has no effect and tool search stays off The set of capabilities Claude Code sends grows over releases. For current beta header strings, see the [beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>); test your gateway against new Claude Code releases rather than pinning to an observed list.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -229,7 +229,7 @@ Feature| Header and body pair| Symptom when broken| Remediation ---|---|---|--- -[Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude 4.6 and later, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead +[Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude Opus 4.6, Claude Sonnet 4.6, Claude Haiku 5.5, Claude Fable 5, and later models, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead [Context management](<https://platform.claude.com/docs/en/build-with-claude/context-editing>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -192,7 +192,7 @@ Header| What to return and why ---|--- -`content-type`| Return `text/event-stream` on streamed Anthropic Messages-format responses, and `application/vnd.amazon.eventstream`, unmodified, on Amazon Bedrock-format responses, where [a different type fails the request](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Streaming lists which connections run stall detection on these streams +`content-type`| Return `text/event-stream` on streamed Anthropic Messages-format responses, and `application/vnd.amazon.eventstream`, unmodified, on Amazon Bedrock-format responses, where [a different type fails the request](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>) `retry-after`| Return integer seconds rather than an HTTP date. Claude Code waits at least that long before the next [automatic retry](</docs/en/errors#automatic-retries>), and outside [`CLAUDE_CODE_RETRY_WATCHDOG`](</docs/en/env-vars>) sessions a value above 60 stops the retries and shows the error at once `x-should-retry`| Pass the upstream’s value through unchanged. Claude Code reads this header as one input when deciding whether to retry a failed request: `true` marks the response retryable and `false` marks it not retryable. For retry counts, backoff, and which failures Claude Code retries, see [automatic retries](</docs/en/errors#automatic-retries>) `anthropic-ratelimit-unified-*`| Forward the upstream’s values unchanged on every response. Claude Code reads them on successful responses to show usage against plan limits to developers signed in with claude.ai, and on a `429` to tell a plan limit or spend cap from a temporary throttle; see [usage limits](</docs/en/errors#usage-limits>)
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -53,7 +53,7 @@ * Inference requests post to `/v1/messages?beta=true` * The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict` -A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. +A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. Sessions that go through a gateway aren’t eligible for the HIPAA configuration. [Check how developers sign in and connect](</docs/en/hipaa-setup#check-how-developers-sign-in-and-connect>) lists which sign-in and connection methods are. See [The HIPAA configuration behind a gateway](</docs/en/llm-gateway-rollout#the-hipaa-configuration-behind-a-gateway>). The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -61,7 +61,13 @@ Streaming -Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. Deliver each response’s full event sequence without dropping, duplicating, or reordering events. When an Amazon Bedrock guardrail blocks a reply, forward the events it sends unchanged, even when they reference a content block whose `content_block_stop` already arrived. [AWS Guardrails](</docs/en/amazon-bedrock#aws-guardrails>) describes how that reply ends. When any other event references a content block whose `content_block_start` never arrived, or a block whose `content_block_stop` already arrived, Claude Code stops reading the stream at that event instead of applying it, so a duplicated `content_block_stop` can’t run the same tool call twice. [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) describes what the user sees, under the `Part of the response never arrived` and `The response stream was malformed` variants. Relay each response through its final `message_delta` and `message_stop` events before ending the body. A body that ends after a `message_delta` carrying a `stop_reason`, with no content block still open and no content block event after that frame, counts as complete even when `message_stop` is missing. A body that your gateway ends cleanly any earlier, once a content block has started, is treated the same as a dropped connection: [Automatic retries](</docs/en/errors#automatic-retries>) says when Claude Code re-issues the request, and [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) covers what it keeps once visible content has arrived. Claude Code keeps the `stop_reason` a `message_delta` delivers, so a later usage-only `message_delta` whose `delta` has `stop_reason: null` or no `stop_reason` key doesn’t clear it. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well, because Claude Code aborts a streaming response once no bytes reach it for [five minutes by default](</docs/en/network-config#streaming-idle-watchdogs>). During a long thinking pause, the upstream’s SSE `ping` events can be the only bytes on the stream. If your gateway strips or buffers them, Claude Code aborts the response partway through the pause. When you translate from an upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, emit your own `ping` events during silent gaps. +Claude Code reads each streaming inference response event by event as it arrives, so the way your gateway relays the stream affects what the user sees: + + * If your gateway buffers a response until it is complete, Claude Code stalls. + * Claude Code expects each response’s full event sequence, in order, through the final `message_delta` and `message_stop` events. If the body ends cleanly after a content block has started but before that final `message_delta`, Claude Code treats the response as a dropped connection. [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) describes what the user sees then, and [Automatic retries](</docs/en/errors#automatic-retries>) says when Claude Code re-issues the request instead. + * When an Amazon Bedrock guardrail blocks a reply, the events Bedrock sends can reference a content block whose `content_block_stop` already arrived, and Claude Code relies on receiving them as sent. [AWS Guardrails](</docs/en/amazon-bedrock#aws-guardrails>) describes how that reply ends. + * Claude Code aborts a streaming response once no bytes reach it for longer than its [streaming idle timeout](</docs/en/network-config#streaming-idle-watchdogs>). During a long thinking pause, the upstream’s SSE `ping` events can be the only bytes on the stream, so a gateway that strips or buffers them can trip that timeout partway through a response. A gateway that translates from an upstream without pings, such as Amazon Bedrock’s binary event stream, has the same gap unless it emits its own `ping` events. + * On the Amazon Bedrock InvokeModel format, Claude Code reads the `/model/{model}/invoke-with-response-stream` response as the binary `application/vnd.amazon.eventstream` body Bedrock returns, and can’t parse it once a gateway converts it to server-sent events or rewrites that `Content-Type` header. [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>) describes what the user sees then. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -227,7 +227,7 @@ [Context management](<https://platform.claude.com/docs/en/build-with-claude/context-editing>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` -[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`, which removes the format and task budget settings but not effort +[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`, which removes the format and task budget settings but not effort. To remove only the format, they can set [`CLAUDE_CODE_DISABLE_STRUCTURED_OUTPUTS=1`](</docs/en/env-vars>) instead, which requires v2.1.288 or later [Prompt caching](</docs/en/prompt-caching>)| No beta pairing. Claude Code attaches `cache_control` markers to `system` blocks and to `messages` entries, including `role: "system"` entries appended mid-conversation| No error: the conversation bills as uncached input on every turn, visible as high `input_tokens` with little or no cache activity in `usage`| Forward `cache_control` unchanged wherever it appears, and don’t convert block-form `system` or message content to plain strings [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| No error: Claude Code falls back to a character-based estimate, so `/context` shows approximate counts| Expose the endpoint for exact token counts @@ -334,7 +334,7 @@ The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry uses `display_name` as its name when the gateway sends one that differs from the `id`. Otherwise the entry shows the model’s name when Claude Code [recognizes the `id`](</docs/en/model-config#customize-pinned-model-display-and-capabilities>), and the `id` when it doesn’t. For example, an entry with the `id` `my-gateway-claude-sonnet-4-6` and no `display_name` appears as `Sonnet 4.6`. Discovery adds only models that the [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) allows. Each entry also shows the model’s `description`, collapsed to one line. An entry without a `description` reads “From gateway” instead. Before v2.1.257, every discovered entry read “From gateway”. A discovered ID doesn’t get its own row when it matches a row already in the picker: * Same ID: the discovered ID exactly matches an existing row’s ID, or the two IDs are spellings of the same [Fable](</docs/en/model-config#work-with-fable>) version. - * Same model as a built-in alias: when a discovered explicit ID names the model that a built-in alias currently resolves to, the picker shows only the alias row. For example, while `sonnet` resolves to `claude-sonnet-5-5`, a discovered `claude-sonnet-5-5` collapses into the `sonnet` row, and a discovered `claude-sonnet-5` still gets its own row. Before v2.1.197, Claude Code didn’t fold these IDs into built-in rows, so the ID an alias resolved to also got its own “From gateway” row. + * Same model as a built-in alias: when a discovered explicit ID names the model that a built-in alias currently resolves to, the picker shows only the alias row. For example, while `sonnet` resolves to `claude-sonnet-5-5`, a discovered `claude-sonnet-5-5` collapses into the `sonnet` row, and a discovered `claude-sonnet-5` still gets its own row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -61,7 +61,7 @@ Streaming -Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. Deliver each response’s full event sequence without dropping, duplicating, or reordering events. When an event references a content block whose `content_block_start` never arrived, or a block whose `content_block_stop` already arrived, Claude Code stops reading the stream at that event instead of applying it, so a duplicated `content_block_stop` can’t run the same tool call twice. [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) describes what the user sees, under the `Part of the response never arrived` and `The response stream was malformed` variants. Relay each response through its final `message_delta` and `message_stop` events before ending the body. A body that ends after a `message_delta` carrying a `stop_reason`, with no content block still open and no content block event after that frame, counts as complete even when `message_stop` is missing. A body that your gateway ends cleanly any earlier, once a content block has started, is treated the same as a dropped connection: [Automatic retries](</docs/en/errors#automatic-retries>) says when Claude Code re-issues the request, and [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) covers what it keeps once visible content has arrived. Claude Code keeps the `stop_reason` a `message_delta` delivers, so a later usage-only `message_delta` whose `delta` has `stop_reason: null` or no `stop_reason` key doesn’t clear it. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well, because Claude Code aborts a streaming response once no bytes reach it for [five minutes by default](</docs/en/network-config#streaming-idle-watchdogs>). During a long thinking pause, the upstream’s SSE `ping` events can be the only bytes on the stream. If your gateway strips or buffers them, Claude Code aborts the response partway through the pause. When you translate from an upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, emit your own `ping` events during silent gaps. +Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. Deliver each response’s full event sequence without dropping, duplicating, or reordering events. When an Amazon Bedrock guardrail blocks a reply, forward the events it sends unchanged, even when they reference a content block whose `content_block_stop` already arrived. [AWS Guardrails](</docs/en/amazon-bedrock#aws-guardrails>) describes how that reply ends. When any other event references a content block whose `content_block_start` never arrived, or a block whose `content_block_stop` already arrived, Claude Code stops reading the stream at that event instead of applying it, so a duplicated `content_block_stop` can’t run the same tool call twice. [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) describes what the user sees, under the `Part of the response never arrived` and `The response stream was malformed` variants. Relay each response through its final `message_delta` and `message_stop` events before ending the body. A body that ends after a `message_delta` carrying a `stop_reason`, with no content block still open and no content block event after that frame, counts as complete even when `message_stop` is missing. A body that your gateway ends cleanly any earlier, once a content block has started, is treated the same as a dropped connection: [Automatic retries](</docs/en/errors#automatic-retries>) says when Claude Code re-issues the request, and [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) covers what it keeps once visible content has arrived. Claude Code keeps the `stop_reason` a `message_delta` delivers, so a later usage-only `message_delta` whose `delta` has `stop_reason: null` or no `stop_reason` key doesn’t clear it. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well, because Claude Code aborts a streaming response once no bytes reach it for [five minutes by default](</docs/en/network-config#streaming-idle-watchdogs>). During a long thinking pause, the upstream’s SSE `ping` events can be the only bytes on the stream. If your gateway strips or buffers them, Claude Code aborts the response partway through the pause. When you translate from an upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, emit your own `ping` events during silent gaps. ### @@ -224,10 +224,10 @@ Feature| Header and body pair| Symptom when broken| Remediation ---|---|---|--- [Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude 4.6 and later, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead -[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-editing>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) +[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-editing>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` -[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together +[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together, or have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`, which removes the format and task budget settings but not effort [Prompt caching](</docs/en/prompt-caching>)| No beta pairing. Claude Code attaches `cache_control` markers to `system` blocks and to `messages` entries, including `role: "system"` entries appended mid-conversation| No error: the conversation bills as uncached input on every turn, visible as high `input_tokens` with little or no cache activity in `usage`| Forward `cache_control` unchanged wherever it appears, and don’t convert block-form `system` or message content to plain strings [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| No error: Claude Code falls back to a character-based estimate, so `/context` shows approximate counts| Expose the endpoint for exact token counts @@ -244,6 +244,7 @@ * When the upstream rejects the `thinking` field, a mid-conversation system message, or the `cache_control` marker on such a message, Claude Code retries the request and disables the rejected capability for the rest of the conversation * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), including with a `400` whose message says the block is `bound to a different conversation`, Claude Code removes earlier thinking blocks from the request, retries, and keeps them out of every later request. New responses still include thinking * When the gateway or its upstream rejects the [advisor tool](</docs/en/advisor>) entry in `tools` as an unrecognized tool type, Claude Code retries the request once without that entry and its `anthropic-beta` value. Later requests to that base URL leave the advisor out until Claude Code exits, and `/advisor` is unavailable to the developer for that time. Claude Code recognizes this rejection by a `400` or `422` response whose message names the tool type after `Input tag`, such as `Input tag 'advisor_20260301'`. Before v2.1.280, Claude Code didn’t retry this rejection + * When the upstream rejects `output_config.effort`, Claude Code retries the request without effort and leaves it out of later requests to that model until Claude Code exits. Claude Code recognizes this rejection by a `400` whose message names `output_config.effort` together with `Extra inputs are not permitted`, or says the model doesn’t support the effort parameter * Claude Code doesn’t retry rejections of context management or tool schema fields, so those `400` errors reach the developer The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. @@ -254,7 +255,23 @@ Disable pre-release capabilities -`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields, including context management and the beta tool fields. The variable doesn’t affect adaptive reasoning, which is selected by model rather than by beta. It never suppresses the OAuth capability that subscription authentication requires. When a host platform that embeds Claude Code sets [`CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`](</docs/en/env-vars>), `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` doesn’t stop auto mode sessions on Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or a [Claude apps gateway](</docs/en/claude-apps-gateway>) from asking the server for [classifier review](</docs/en/permission-modes#server-side-classifier-review>). That review adds an `anthropic-beta` value and a `safeguards` request field. Set `CLAUDE_CODE_AUTO_MODE_SERVER=0` to stop it there. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/managed-settings>). What Claude Code sends with that override in place depends on how you connect: +When your gateway or its upstream rejects pre-release `anthropic-beta` values or the body fields that pair with them, and you can’t forward both halves, have developers set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`. With the variable set, Claude Code stops sending pre-release capabilities and the `anthropic-beta` values that pair with them, including: + + * Context management and its `context_management` body field + * The beta tool schema fields, such as `strict` and `defer_loading`. The standard `name`, `description`, `input_schema`, and `cache_control` tool fields stay + * The structured-output `output_config.format` field. Requires Claude Code v2.1.287 or later + * The `output_config.task_budget` field + * [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>), so every MCP tool loads upfront unless your organization keeps it on through managed settings + +The variable doesn’t strip every `anthropic-beta` value. What it leaves in place includes: + + * The `anthropic-beta` values for extended context, interleaved thinking, and effort, which cloud providers also accept + * The `output_config.effort` field. Automatic retry and error forwarding covers an upstream that rejects it + * The adaptive reasoning `thinking` field, which has no beta header + * The OAuth `anthropic-beta` value that subscription authentication requires + * Header values and body fields developers add themselves through [`ANTHROPIC_BETAS`](</docs/en/env-vars>) or [`CLAUDE_CODE_EXTRA_BODY`](</docs/en/env-vars>) + +When a host platform that embeds Claude Code sets [`CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`](</docs/en/env-vars>), `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` doesn’t stop auto mode sessions on Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or a [Claude apps gateway](</docs/en/claude-apps-gateway>) from asking the server for [classifier review](</docs/en/permission-modes#server-side-classifier-review>). That review adds an `anthropic-beta` value and a `safeguards` request field. Set `CLAUDE_CODE_AUTO_MODE_SERVER=0` to stop it there. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/managed-settings>). What Claude Code sends with that override in place depends on how you connect: * On a direct connection, or through a gateway set with `ANTHROPIC_BASE_URL`, Claude Code keeps sending the tool-search beta header, `defer_loading` tool fields, and `tool_reference` blocks, and strips the rest * On a cloud provider, or signed in through a [Claude apps gateway](</docs/en/claude-apps-gateway>), the override has no effect
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -290,7 +290,7 @@ The request is `GET /v1/models?limit=1000` with a timeout of 3 seconds by default, and any redirect is treated as failure so the credential can’t leak to a redirect target. A gateway that responds slower than the timeout, or one that redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. To give a slow gateway longer, set [`CLAUDE_CODE_GATEWAY_MODEL_DISCOVERY_TIMEOUT_MS`](</docs/en/env-vars#variables>). The variable requires Claude Code v2.1.269 or later. Claude Code sends the discovery request with both credential headers below and omits a header whose value doesn’t resolve. Sending both headers requires Claude Code v2.1.248 or later. Earlier versions send only `Authorization` when `ANTHROPIC_AUTH_TOKEN` is set and only `x-api-key` otherwise. - * `Authorization`: `ANTHROPIC_AUTH_TOKEN` as a bearer token, otherwise the [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value as a bearer token. In that case Claude Code waits for the helper to return before sending the request. + * `Authorization`: `ANTHROPIC_AUTH_TOKEN` as a bearer token, otherwise the [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value as a bearer token. * `x-api-key`: the API key Claude Code resolved, such as `ANTHROPIC_API_KEY`. When a helper value is the only credential, this header carries it too, so the value arrives in both headers. Claude Code also sends any headers from `ANTHROPIC_CUSTOM_HEADERS`. When a custom header has a non-empty value, Claude Code sends it in place of a built-in header of the same name, matching names case-insensitively. When neither credential header’s value resolves, Claude Code skips discovery and writes a `[gatewayDiscovery] skipped` line to the debug log of a `claude --debug` session. If you supply a credential only through `ANTHROPIC_CUSTOM_HEADERS`, Claude Code still skips discovery. Claude Code reads `id`, the optional `display_name`, and the optional `description` from each entry in the response’s `data` array:
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -61,7 +61,7 @@ Streaming -Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. Deliver each response’s full event sequence without dropping, duplicating, or reordering events. When an event references a content block whose `content_block_start` never arrived, or a block whose `content_block_stop` already arrived, Claude Code stops reading the stream at that event instead of applying it, so a duplicated `content_block_stop` can’t run the same tool call twice. [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) describes what the user sees, under the `Part of the response never arrived` and `The response stream was malformed` variants. Relay each response through its final `message_delta` and `message_stop` events before ending the body. A body that ends after a `message_delta` carrying a `stop_reason`, with no content block still open and no content block event after that frame, counts as complete even when `message_stop` is missing. A body that your gateway ends cleanly any earlier, once a content block has started, is treated the same as a dropped connection: [Automatic retries](</docs/en/errors#automatic-retries>) says when Claude Code re-issues the request, and [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) covers what it keeps once visible content has arrived. Claude Code keeps the `stop_reason` a `message_delta` delivers, so a later usage-only `message_delta` whose `delta` has `stop_reason: null` or no `stop_reason` key doesn’t clear it. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. An upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, leaves those pauses with nothing to forward. When translating from such an upstream, emit your own `ping` events during silent gaps. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). +Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. Deliver each response’s full event sequence without dropping, duplicating, or reordering events. When an event references a content block whose `content_block_start` never arrived, or a block whose `content_block_stop` already arrived, Claude Code stops reading the stream at that event instead of applying it, so a duplicated `content_block_stop` can’t run the same tool call twice. [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) describes what the user sees, under the `Part of the response never arrived` and `The response stream was malformed` variants. Relay each response through its final `message_delta` and `message_stop` events before ending the body. A body that ends after a `message_delta` carrying a `stop_reason`, with no content block still open and no content block event after that frame, counts as complete even when `message_stop` is missing. A body that your gateway ends cleanly any earlier, once a content block has started, is treated the same as a dropped connection: [Automatic retries](</docs/en/errors#automatic-retries>) says when Claude Code re-issues the request, and [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) covers what it keeps once visible content has arrived. Claude Code keeps the `stop_reason` a `message_delta` delivers, so a later usage-only `message_delta` whose `delta` has `stop_reason: null` or no `stop_reason` key doesn’t clear it. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well, because Claude Code aborts a streaming response once no bytes reach it for [five minutes by default](</docs/en/network-config#streaming-idle-watchdogs>). During a long thinking pause, the upstream’s SSE `ping` events can be the only bytes on the stream. If your gateway strips or buffers them, Claude Code aborts the response partway through the pause. When you translate from an upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, emit your own `ping` events during silent gaps. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -317,7 +317,7 @@ The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry uses `display_name` as its name when the gateway sends one that differs from the `id`. Otherwise the entry shows the model’s name when Claude Code [recognizes the `id`](</docs/en/model-config#customize-pinned-model-display-and-capabilities>), and the `id` when it doesn’t. For example, an entry with the `id` `my-gateway-claude-sonnet-4-6` and no `display_name` appears as `Sonnet 4.6`. Discovery adds only models that the [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) allows. Each entry also shows the model’s `description`, collapsed to one line. An entry without a `description` reads “From gateway” instead. Before v2.1.257, every discovered entry read “From gateway”. A discovered ID doesn’t get its own row when it matches a row already in the picker: * Same ID: the discovered ID exactly matches an existing row’s ID, or the two IDs are spellings of the same [Fable](</docs/en/model-config#work-with-fable>) version. - * Same model as a built-in alias: when a discovered explicit ID names the model that a built-in alias currently resolves to, the picker shows only the alias row. For example, while `sonnet` resolves to `claude-sonnet-5`, a discovered `claude-sonnet-5` collapses into the `sonnet` row, and a discovered `claude-sonnet-4-6` still gets its own row. Before v2.1.197, Claude Code didn’t fold these IDs into built-in rows, so `claude-sonnet-5` also got its own “From gateway” row. + * Same model as a built-in alias: when a discovered explicit ID names the model that a built-in alias currently resolves to, the picker shows only the alias row. For example, while `sonnet` resolves to `claude-sonnet-5-5`, a discovered `claude-sonnet-5-5` collapses into the `sonnet` row, and a discovered `claude-sonnet-5` still gets its own row. Before v2.1.197, Claude Code didn’t fold these IDs into built-in rows, so the ID an alias resolved to also got its own “From gateway” row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -61,7 +61,7 @@ Streaming -Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. An upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, leaves those pauses with nothing to forward. When translating from such an upstream, emit your own `ping` events during silent gaps. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). +Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. Deliver each response’s full event sequence without dropping, duplicating, or reordering events. When an event references a content block whose `content_block_start` never arrived, or a block whose `content_block_stop` already arrived, Claude Code stops reading the stream at that event instead of applying it, so a duplicated `content_block_stop` can’t run the same tool call twice. [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) describes what the user sees, under the `Part of the response never arrived` and `The response stream was malformed` variants. Relay each response through its final `message_delta` and `message_stop` events before ending the body. A body that ends after a `message_delta` carrying a `stop_reason`, with no content block still open and no content block event after that frame, counts as complete even when `message_stop` is missing. A body that your gateway ends cleanly any earlier, once a content block has started, is treated the same as a dropped connection: [Automatic retries](</docs/en/errors#automatic-retries>) says when Claude Code re-issues the request, and [The response above may be incomplete](</docs/en/errors#the-response-above-may-be-incomplete>) covers what it keeps once visible content has arrived. Claude Code keeps the `stop_reason` a `message_delta` delivers, so a later usage-only `message_delta` whose `delta` has `stop_reason: null` or no `stop_reason` key doesn’t clear it. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. An upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, leaves those pauses with nothing to forward. When translating from such an upstream, emit your own `ping` events during silent gaps. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). ### @@ -148,7 +148,7 @@ * Custom base URL: off by default, because a proxy that rejects unknown headers would fail the request. To receive them, set [`CLAUDE_CODE_GATEWAY_HINT_HEADERS=1`](</docs/en/env-vars>) for your developers, for example in the `env` block of [managed settings](</docs/en/managed-settings>) * Any other backend, including Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, and Claude Platform on AWS: sent only when `CLAUDE_CODE_GATEWAY_HINT_HEADERS=1` is set -Setting `CLAUDE_CODE_GATEWAY_HINT_HEADERS` to `0` stops the headers on every connection. The headers carry only what the rows below list: fixed vocabularies, tool names, and durations, never prompt text or file contents. Every value is printable ASCII. +Setting `CLAUDE_CODE_GATEWAY_HINT_HEADERS` to `0` stops the headers on every connection. The headers carry only what the rows below list: fixed vocabularies, tool names, durations, and a random prompt identifier, never prompt text or file contents. Every value is printable ASCII. Header| Description ---|--- @@ -157,6 +157,7 @@ `x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the context window approached capacity, `manual` for `/compact`, or `reactive` when the API rejected a request as too long. Absent on every other request `x-claude-code-context-compacted`| Present once, on the first main-conversation request after a compaction, with the same values as `x-claude-code-compaction`. The conversation prefix before this request is no longer used, so a cache keyed on it can be dropped `x-claude-code-prev-tool-durations`| Measured run time of the tool calls whose results this request carries, as `<name>=<ms>;<name>=<ms>`, for example `Bash=742;Read=9`. Sent on the next request of the same conversation after a batch of tool calls, from the main session or a subagent +`x-claude-code-prompt-id`| Random UUID that identifies the user prompt a request serves. Requests serving one prompt share the value, including the turns of subagents that prompt started. Requests not attributed to a prompt omit it. Use it to group a session’s requests by prompt. Requires Claude Code v2.1.283 or later Before parsing `x-claude-code-prev-tool-durations`, check how Claude Code builds the value and what it leaves out: @@ -253,7 +254,7 @@ Disable pre-release capabilities -`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. The variable doesn’t affect adaptive reasoning, which is selected by model rather than by beta. It never suppresses the OAuth capability that subscription authentication requires. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/managed-settings>). What Claude Code sends with that override in place depends on how you connect: +`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields, including context management and the beta tool fields. The variable doesn’t affect adaptive reasoning, which is selected by model rather than by beta. It never suppresses the OAuth capability that subscription authentication requires. When a host platform that embeds Claude Code sets [`CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`](</docs/en/env-vars>), `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` doesn’t stop auto mode sessions on Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or a [Claude apps gateway](</docs/en/claude-apps-gateway>) from asking the server for [classifier review](</docs/en/permission-modes#server-side-classifier-review>). That review adds an `anthropic-beta` value and a `safeguards` request field. Set `CLAUDE_CODE_AUTO_MODE_SERVER=0` to stop it there. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/managed-settings>). What Claude Code sends with that override in place depends on how you connect: * On a direct connection, or through a gateway set with `ANTHROPIC_BASE_URL`, Claude Code keeps sending the tool-search beta header, `defer_loading` tool fields, and `tool_reference` blocks, and strips the rest * On a cloud provider, or signed in through a [Claude apps gateway](</docs/en/claude-apps-gateway>), the override has no effect
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -242,6 +242,7 @@ * When the upstream rejects the `thinking` field, a mid-conversation system message, or the `cache_control` marker on such a message, Claude Code retries the request and disables the rejected capability for the rest of the conversation * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), including with a `400` whose message says the block is `bound to a different conversation`, Claude Code removes earlier thinking blocks from the request, retries, and keeps them out of every later request. New responses still include thinking + * When the gateway or its upstream rejects the [advisor tool](</docs/en/advisor>) entry in `tools` as an unrecognized tool type, Claude Code retries the request once without that entry and its `anthropic-beta` value. Later requests to that base URL leave the advisor out until Claude Code exits, and `/advisor` is unavailable to the developer for that time. Claude Code recognizes this rejection by a `400` or `422` response whose message names the tool type after `Input tag`, such as `Input tag 'advisor_20260301'`. Before v2.1.280, Claude Code didn’t retry this rejection * Claude Code doesn’t retry rejections of context management or tool schema fields, so those `400` errors reach the developer The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -135,6 +135,37 @@ `x-claude-code-parent-agent-id`| Identifier of the agent that spawned the requesting agent, present only for nested agents Subagent IDs are generated fresh each time Claude Code spawns a subagent. Teammate agents, the named members of an [agent team](</docs/en/agent-teams>), reuse a stable name-based ID across reconnections. In both cases the ID identifies an agent, not a person or a device, so don’t treat the agent ID header as a user identifier. If your developers set `ANTHROPIC_CUSTOM_HEADERS`, those headers appear on requests as well. + +### + +​ + +Gateway hint headers + +Claude Code can also send routing hints: per-request facts a gateway or router can use to schedule, cache, or attribute a request. Requires Claude Code v2.1.273 or later. Whether a request carries them depends on where Claude Code sends it: + + * Direct connection to the Anthropic API: sent by default + * Custom base URL: off by default, because a proxy that rejects unknown headers would fail the request. To receive them, set [`CLAUDE_CODE_GATEWAY_HINT_HEADERS=1`](</docs/en/env-vars>) for your developers, for example in the `env` block of [managed settings](</docs/en/managed-settings>) + * Any other backend, including Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, and Claude Platform on AWS: sent only when `CLAUDE_CODE_GATEWAY_HINT_HEADERS=1` is set + +Setting `CLAUDE_CODE_GATEWAY_HINT_HEADERS` to `0` stops the headers on every connection. The headers carry only what the rows below list: fixed vocabularies, tool names, and durations, never prompt text or file contents. Every value is printable ASCII. + +Header| Description +---|--- +`x-claude-code-request-class`| What kind of request this is: `main` for a turn of the main conversation, `subagent` for a turn of a [subagent](</docs/en/sub-agents>), `workflow` for an agent running inside a workflow, `compaction` for the summarization request that compacts a conversation, or `auxiliary` for side requests such as session titles, classifiers, and summaries. Sent on every request +`x-claude-code-agent-type`| The kind of subagent that issued the request: a built-in agent type name such as `Explore`, `Plan`, or `general-purpose`, or `custom` for a user-defined agent, `teammate` for an [agent team](</docs/en/agent-teams>) member running in the lead’s process, or `fork` for a [fork](</docs/en/sub-agents#fork-the-current-conversation>). Present only on a subagent’s own turns; a subagent’s compaction or side requests keep the agent ID but carry no type. A user-chosen agent name is never sent +`x-claude-code-compaction`| Present on the request that summarizes the conversation during a [compaction](</docs/en/prompt-caching#compacting-the-conversation>). The value says what triggered it: `auto` when the context window approached capacity, `manual` for `/compact`, or `reactive` when the API rejected a request as too long. Absent on every other request +`x-claude-code-context-compacted`| Present once, on the first main-conversation request after a compaction, with the same values as `x-claude-code-compaction`. The conversation prefix before this request is no longer used, so a cache keyed on it can be dropped +`x-claude-code-prev-tool-durations`| Measured run time of the tool calls whose results this request carries, as `<name>=<ms>;<name>=<ms>`, for example `Bash=742;Read=9`. Sent on the next request of the same conversation after a batch of tool calls, from the main session or a subagent + +Before parsing `x-claude-code-prev-tool-durations`, check how Claude Code builds the value and what it leaves out: + + * Entries: one per tool call that ran, in the order its result was collected, in whole milliseconds + * Cap: Claude Code sends at most 32 entries and 4 KB, keeping the first entries + * Encoding: tool names are percent-encoded, covering `%`, `;`, `=`, comma, space, and any character outside printable ASCII + * Parsing: split on `;`, then on `=`, and decode each name + * Absence: compaction calls, side requests, and the first request of a new prompt never carry it. Don’t read a missing header as a turn that ran no tools + * Times: each one excludes permission prompts and hooks, and parallel tool calls each report their own time, so the entries don’t add up to the gap between requests ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -6,7 +6,9 @@ This page covers: * API formats and the endpoints to serve for each + * Client behavior by connection method: how model IDs, `anthropic-beta` values, request fields, and defaults differ between the formats and a Claude apps gateway sign-in * Request headers: which must reach the upstream and which your gateway can consume + * Response headers: what to return so stall detection, retries, and usage limit display work * The system prompt attribution block and how it interacts with prompt caching * Feature pass-through: what breaks when headers or body fields are stripped * Model discovery @@ -72,7 +74,48 @@ * When the client speaks the Amazon Bedrock or Google Cloud’s Agent Platform format, Claude Code sends only the subset of its full capability set that those providers accept * When the client speaks the Anthropic Messages format, Claude Code sends the full set, even if your gateway forwards to an Amazon Bedrock or Google Cloud’s Agent Platform upstream -Bridging that difference is your gateway’s job. Feature pass-through describes what breaks when it doesn’t. +Bridging that difference is your gateway’s job. Feature pass-through describes what breaks when it doesn’t. If your upstream is Amazon Bedrock or Google Cloud’s Agent Platform, you can avoid the bridging by exposing that provider’s format instead. [Route to a cloud provider through a gateway](</docs/en/llm-gateway-connect#route-to-a-cloud-provider-through-a-gateway>) shows the client configuration for that format. + +## + +​ + +How the connection method changes client behavior + +The way a developer connects to your gateway determines which model IDs, `anthropic-beta` values, and request fields Claude Code sends, and which defaults it applies. Your gateway sees one of three client behaviors: + + * **Amazon Bedrock or Agent Platform format** : the developer sets `CLAUDE_CODE_USE_BEDROCK=1` with `ANTHROPIC_BEDROCK_BASE_URL`, or `CLAUDE_CODE_USE_VERTEX=1` with `ANTHROPIC_VERTEX_BASE_URL`, pointing at your gateway. Claude Code uses that provider’s model IDs, request fields, and defaults. + * **Anthropic Messages format** : the developer sets `ANTHROPIC_BASE_URL` to your gateway. Claude Code treats the gateway as the Claude API and can’t tell which upstream you forward to. + * **Claude apps gateway sign-in** : the developer signs in to a [Claude apps gateway](</docs/en/claude-apps-gateway>). That gateway speaks the Anthropic Messages format but can route to any upstream, so Claude Code sends only the `anthropic-beta` values and model-capability assumptions that Amazon Bedrock and Agent Platform also accept. + +### + +​ + +Requests and defaults by connection method + +The table below compares the three connection methods, one behavior per row. It leaves out Microsoft Foundry and Claude Platform on AWS, which also use the Anthropic Messages format but which Claude Code reaches through their own variables. For those, see the [Microsoft Foundry](</docs/en/microsoft-foundry>) and [Claude Platform on AWS](</docs/en/claude-platform-on-aws>) pages. + +Behavior| Amazon Bedrock or Agent Platform format| Anthropic Messages format| Claude apps gateway sign-in +---|---|---|--- +Model IDs in requests by default| The provider’s form, such as `us.anthropic.claude-opus-4-8` on Amazon Bedrock| Anthropic IDs, such as `claude-opus-4-8`| Anthropic IDs +`anthropic-beta` values sent| The subset Amazon Bedrock and Agent Platform accept| The full set described under feature pass-through, unless the developer sets `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`| The subset Amazon Bedrock and Agent Platform accept +Request fields for a model ID Claude Code doesn’t recognize, such as a gateway alias| Thinking with a fixed budget rather than adaptive reasoning, and no effort or context management fields| Everything current Claude models accept on the Claude API, including adaptive reasoning, effort, and context management, which an Amazon Bedrock or Agent Platform upstream can reject| Same as the Amazon Bedrock or Agent Platform format +One-hour [prompt cache TTL](</docs/en/prompt-caching#choose-the-ttl-yourself>) when a developer opts in| Requested through the `ttl` field in `cache_control`, with no beta value| Requested through the `ttl` field plus an `extended-cache-ttl` value in `anthropic-beta`, which you must forward| See the Claude apps gateway [availability and limitations](</docs/en/claude-apps-gateway#availability-and-limitations>) table +Model for [background tasks](</docs/en/costs#background-token-usage>) unless `ANTHROPIC_DEFAULT_HAIKU_MODEL` pins one| The default Sonnet model, or the main model once one is selected, as the [Amazon Bedrock](</docs/en/amazon-bedrock#4-pin-model-versions>) and [Agent Platform](</docs/en/google-vertex-ai#5-pin-model-versions>) pages describe| The main model, or the default Haiku model when `ANTHROPIC_API_KEY` or `apiKeyHelper` supplies an Anthropic Console key and `ANTHROPIC_AUTH_TOKEN` is unset| The main model + +For the features each connection supports and the telemetry it sends to Anthropic by default, see [Feature availability](</docs/en/feature-availability#availability-by-model-provider>) and [Default behaviors by API provider](</docs/en/data-usage#default-behaviors-by-api-provider>). + +### + +​ + +Settings for unrecognized model IDs + +Two client-side settings change what Claude Code assumes for a model ID it doesn’t recognize, whichever connection method the developer uses: + + * **Context window** : Claude Code assumes 200K, or 1M when the ID carries `[1m]`. To declare the real window, see [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) + * **Capabilities** : to give a gateway alias the capabilities of the model behind it, map that model’s Anthropic ID to your alias with a [`modelOverrides`](</docs/en/errors#unrecognized-model-id-on-a-request>) entry in the settings you distribute. For where the `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` variables apply, see feature pass-through ## @@ -100,6 +143,21 @@ Forward as open lists Treat the headers and body fields as open lists, not closed ones. Claude Code gains capabilities over releases, and they arrive as new `anthropic-beta` values, new request body fields, and occasionally new `anthropic-*` or `x-claude-code-*` headers. When forwarding to an Anthropic-format upstream, pass `anthropic-*` request headers and request body fields through unchanged rather than allowlisting the ones you see today. A gateway pinned to an observed list strips the next capability’s header or field and breaks it on the release that introduces it. The exception is a non-Anthropic upstream such as Amazon Bedrock or Google Cloud’s Agent Platform, where bridging the schema difference is the gateway’s job; see feature pass-through. + +## + +​ + +Response headers + +Claude Code reads these response headers to detect stalled streams, to decide whether and when to retry, and to show usage limits. The table lists what to return for each. Also forward error response bodies unmodified, so Claude Code’s capability-rejection recovery can match the upstream’s error wording. + +Header| What to return and why +---|--- +`content-type`| Return `text/event-stream` on streamed Anthropic Messages-format responses, and `application/vnd.amazon.eventstream`, unmodified, on Amazon Bedrock-format responses, where [a different type fails the request](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Streaming lists which connections run stall detection on these streams +`retry-after`| Return integer seconds rather than an HTTP date. Claude Code waits at least that long before the next [automatic retry](</docs/en/errors#automatic-retries>), and outside [`CLAUDE_CODE_RETRY_WATCHDOG`](</docs/en/env-vars>) sessions a value above 60 stops the retries and shows the error at once +`x-should-retry`| Pass the upstream’s value through unchanged. Claude Code reads this header as one input when deciding whether to retry a failed request: `true` marks the response retryable and `false` marks it not retryable. For retry counts, backoff, and which failures Claude Code retries, see [automatic retries](</docs/en/errors#automatic-retries>) +`anthropic-ratelimit-unified-*`| Forward the upstream’s values unchanged on every response. Claude Code reads them on successful responses to show usage against plan limits to developers signed in with claude.ai, and on a `429` to tell a plan limit or spend cap from a temporary throttle; see [usage limits](</docs/en/errors#usage-limits>) ##
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -197,7 +197,7 @@ Request and response -The request is `GET /v1/models?limit=1000` with a 3-second timeout, and any redirect is treated as failure so the credential can’t leak to a redirect target. A gateway that responds slowly or redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. Claude Code sends the discovery request with both credential headers below and omits a header whose value doesn’t resolve. Sending both headers requires Claude Code v2.1.248 or later. Earlier versions send only `Authorization` when `ANTHROPIC_AUTH_TOKEN` is set and only `x-api-key` otherwise. +The request is `GET /v1/models?limit=1000` with a timeout of 3 seconds by default, and any redirect is treated as failure so the credential can’t leak to a redirect target. A gateway that responds slower than the timeout, or one that redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. To give a slow gateway longer, set [`CLAUDE_CODE_GATEWAY_MODEL_DISCOVERY_TIMEOUT_MS`](</docs/en/env-vars#variables>). The variable requires Claude Code v2.1.269 or later. Claude Code sends the discovery request with both credential headers below and omits a header whose value doesn’t resolve. Sending both headers requires Claude Code v2.1.248 or later. Earlier versions send only `Authorization` when `ANTHROPIC_AUTH_TOKEN` is set and only `x-api-key` otherwise. * `Authorization`: `ANTHROPIC_AUTH_TOKEN` as a bearer token, otherwise the [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value as a bearer token. In that case Claude Code waits for the helper to return before sending the request. * `x-api-key`: the API key Claude Code resolved, such as `ANTHROPIC_API_KEY`. When a helper value is the only credential, this header carries it too, so the value arrives in both headers.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -152,10 +152,10 @@ What Claude Code does after an upstream rejection depends on what was rejected: * When the upstream rejects the `thinking` field, a mid-conversation system message, or the `cache_control` marker on such a message, Claude Code retries the request and disables the rejected capability for the rest of the conversation - * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), Claude Code retries the request without the conversation’s earlier thinking blocks and keeps them out of every later request. New responses still include thinking + * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), including with a `400` whose message says the block is `bound to a different conversation`, Claude Code removes earlier thinking blocks from the request, retries, and keeps them out of every later request. New responses still include thinking * Claude Code doesn’t retry rejections of context management or tool schema fields, so those `400` errors reach the developer -The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. +The `bound to a different conversation` rejection comes from the API’s [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>) check, which fails when `system`, `tools`, or earlier `messages` content differs from the request that produced the thinking. A gateway that rewrites any of that content can cause the rejection itself; [Libraries, proxies, and gateways](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#libraries-proxies-gateways>) covers what to pass through unchanged. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -91,7 +91,7 @@ `x-claude-code-agent-id`| Identifier of the [subagent](</docs/en/sub-agents>) that issued the request, present only on requests from an agent Claude Code spawned inside the session. Use it with the session ID to attribute cost to parallel agents `x-claude-code-parent-agent-id`| Identifier of the agent that spawned the requesting agent, present only for nested agents -Subagent IDs are generated fresh for each spawn. Teammate agents, the named members of an [agent team](</docs/en/agent-teams>), reuse a stable name-based ID across reconnections. In both cases the ID identifies an agent, not a person or a device, so don’t treat the agent ID header as a user identifier. If your developers set `ANTHROPIC_CUSTOM_HEADERS`, those headers appear on requests as well. +Subagent IDs are generated fresh each time Claude Code spawns a subagent. Teammate agents, the named members of an [agent team](</docs/en/agent-teams>), reuse a stable name-based ID across reconnections. In both cases the ID identifies an agent, not a person or a device, so don’t treat the agent ID header as a user identifier. If your developers set `ANTHROPIC_CUSTOM_HEADERS`, those headers appear on requests as well. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -46,7 +46,12 @@ Optional endpoints and startup traffic -Token-counting endpoints are the only optional ones: when they’re absent, Claude Code falls back to counting context usage through the inference endpoint instead. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. +Token-counting endpoints are the only optional ones: when they’re absent, Claude Code falls back to a character-based estimate of context usage. Match on the path, not the full URL: + + * Inference requests post to `/v1/messages?beta=true` + * The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict` + +A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. ### @@ -134,7 +139,7 @@ Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together [Prompt caching](</docs/en/prompt-caching>)| No beta pairing. Claude Code attaches `cache_control` markers to `system` blocks and to `messages` entries, including `role: "system"` entries appended mid-conversation| No error: the conversation bills as uncached input on every turn, visible as high `input_tokens` with little or no cache activity in `usage`| Forward `cache_control` unchanged wherever it appears, and don’t convert block-form `system` or message content to plain strings -[Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to counting context usage through the messages endpoint| Expose the endpoint so token counts don’t consume inference requests +[Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| No error: Claude Code falls back to a character-based estimate, so `/context` shows approximate counts| Expose the endpoint for exact token counts The `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` [variables](</docs/en/model-config>) declare model capabilities only in the provider configurations: `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY`, and [`CLAUDE_CODE_USE_MANTLE`](</docs/en/amazon-bedrock#use-the-mantle-endpoint>). They have no effect behind an `ANTHROPIC_BASE_URL` gateway. @@ -144,7 +149,13 @@ Automatic retry and error forwarding -When the upstream rejects the `thinking` field, a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), a mid-conversation system message, or the `cache_control` marker on one of those messages, Claude Code retries the request and disables the rejected capability for the rest of the conversation. Claude Code doesn’t retry context management or tool schema field rejections; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. +What Claude Code does after an upstream rejection depends on what was rejected: + + * When the upstream rejects the `thinking` field, a mid-conversation system message, or the `cache_control` marker on such a message, Claude Code retries the request and disables the rejected capability for the rest of the conversation + * When the upstream rejects a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), Claude Code retries the request without the conversation’s earlier thinking blocks and keeps them out of every later request. New responses still include thinking + * Claude Code doesn’t retry rejections of context management or tool schema fields, so those `400` errors reach the developer + +The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -212,7 +212,7 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry uses `display_name` as its name when the gateway sends one, and the model’s `id` otherwise. Discovery adds only models that the [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) allows. Each entry also shows the model’s `description`, collapsed to one line. An entry without a `description` reads “From gateway” instead. Before v2.1.257, every discovered entry read “From gateway”. A discovered ID doesn’t get its own row when it matches a row already in the picker: +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry uses `display_name` as its name when the gateway sends one that differs from the `id`. Otherwise the entry shows the model’s name when Claude Code [recognizes the `id`](</docs/en/model-config#customize-pinned-model-display-and-capabilities>), and the `id` when it doesn’t. For example, an entry with the `id` `my-gateway-claude-sonnet-4-6` and no `display_name` appears as `Sonnet 4.6`. Discovery adds only models that the [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) allows. Each entry also shows the model’s `description`, collapsed to one line. An entry without a `description` reads “From gateway” instead. Before v2.1.257, every discovered entry read “From gateway”. A discovered ID doesn’t get its own row when it matches a row already in the picker: * Same ID: the discovered ID exactly matches an existing row’s ID, or the two IDs are spellings of the same [Fable](</docs/en/model-config#work-with-fable>) version. * Same model as a built-in alias: when a discovered explicit ID names the model that a built-in alias currently resolves to, the picker shows only the alias row. For example, while `sonnet` resolves to `claude-sonnet-5`, a discovered `claude-sonnet-5` collapses into the `sonnet` row, and a discovered `claude-sonnet-4-6` still gets its own row. Before v2.1.197, Claude Code didn’t fold these IDs into built-in rows, so `claude-sonnet-5` also got its own “From gateway” row.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -177,7 +177,8 @@ * Any `CLAUDE_CODE_USE_*` provider variable is set, even if `ANTHROPIC_BASE_URL` is also set * `ANTHROPIC_BASE_URL` is unset or points at `api.anthropic.com` - * Nonessential traffic is disabled, through [`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`](</docs/en/env-vars>) or organization policy + +Discovery still runs when [nonessential traffic is turned off](</docs/en/llm-gateway-connect#turn-off-traffic-outside-the-gateway-path>), because the request goes only to your gateway. Before v2.1.257, discovery didn’t run while nonessential traffic was turned off. ### @@ -190,11 +191,15 @@ * `Authorization`: `ANTHROPIC_AUTH_TOKEN` as a bearer token, otherwise the [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value as a bearer token. In that case Claude Code waits for the helper to return before sending the request. * `x-api-key`: the API key Claude Code resolved, such as `ANTHROPIC_API_KEY`. When a helper value is the only credential, this header carries it too, so the value arrives in both headers. -Claude Code also sends any headers from `ANTHROPIC_CUSTOM_HEADERS`. When neither credential header’s value resolves, Claude Code skips discovery and writes a `[gatewayDiscovery] skipped` line to the debug log of a `claude --debug` session. Claude Code reads `id` and the optional `display_name` from each entry in the response’s `data` array: +Claude Code also sends any headers from `ANTHROPIC_CUSTOM_HEADERS`. When a custom header has a non-empty value, Claude Code sends it in place of a built-in header of the same name, matching names case-insensitively. When neither credential header’s value resolves, Claude Code skips discovery and writes a `[gatewayDiscovery] skipped` line to the debug log of a `claude --debug` session. If you supply a credential only through `ANTHROPIC_CUSTOM_HEADERS`, Claude Code still skips discovery. Claude Code reads `id`, the optional `display_name`, and the optional `description` from each entry in the response’s `data` array: { "data": [ - { "id": "claude-sonnet-4-6", "display_name": "Claude Sonnet 4.6" }, + { + "id": "claude-sonnet-4-6", + "display_name": "Claude Sonnet 4.6", + "description": "Default model for everyday coding tasks" + }, { "id": "claude-opus-4-8" } ] } @@ -207,7 +212,12 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when the discovered and existing IDs are spellings of the same [Fable](</docs/en/model-config#work-with-fable>) version. A discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Before v2.1.197, Claude Code didn’t fold explicit IDs into built-in entries, so a discovered ID such as `claude-sonnet-5` added its own “From gateway” row alongside the `sonnet` row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry uses `display_name` as its name when the gateway sends one, and the model’s `id` otherwise. Discovery adds only models that the [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) allows. Each entry also shows the model’s `description`, collapsed to one line. An entry without a `description` reads “From gateway” instead. Before v2.1.257, every discovered entry read “From gateway”. A discovered ID doesn’t get its own row when it matches a row already in the picker: + + * Same ID: the discovered ID exactly matches an existing row’s ID, or the two IDs are spellings of the same [Fable](</docs/en/model-config#work-with-fable>) version. + * Same model as a built-in alias: when a discovered explicit ID names the model that a built-in alias currently resolves to, the picker shows only the alias row. For example, while `sonnet` resolves to `claude-sonnet-5`, a discovered `claude-sonnet-5` collapses into the `sonnet` row, and a discovered `claude-sonnet-4-6` still gets its own row. Before v2.1.197, Claude Code didn’t fold these IDs into built-in rows, so `claude-sonnet-5` also got its own “From gateway” row. + +Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. ##
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -1,4 +1,4 @@ -This page documents the requests Claude Code sends to a gateway, including the endpoints it calls, the headers and body fields the gateway must forward, and which features stop working when it doesn’t. It is written for operators configuring a gateway product to work with Claude Code. A running [Claude apps gateway](</docs/en/claude-apps-gateway>) serves a machine-readable version of this contract at `GET /protocol`, covering the same forwarding requirements plus the Claude apps gateway-specific endpoints for SSO sign-in, managed-settings delivery, and telemetry. Claude apps gateway runs from the same `claude` binary as the CLI, so the [Claude apps gateway quickstart](</docs/en/claude-apps-gateway#quickstart>) is the shortest path to a running instance you can fetch the spec from. +This page documents the requests Claude Code sends to a gateway, including the endpoints it calls, the headers and body fields the gateway must forward, and which features stop working when it doesn’t. It is written for operators configuring a gateway product to work with Claude Code. The [Claude apps gateway](</docs/en/claude-apps-gateway>), Anthropic’s self-hosted gateway, serves its own endpoint reference at `GET /protocol`, covering that gateway’s sign-in, inference, managed settings, model discovery, and telemetry endpoints. It is a separate document from this guide. * To roll out an existing or third-party gateway for your organization, see [Roll out an LLM gateway](</docs/en/llm-gateway-rollout>) * If you’re an individual developer authenticating Claude Code to a gateway with a credential you were given, see [Connect Claude Code to an LLM gateway](</docs/en/llm-gateway-connect>) @@ -219,7 +219,7 @@ * [Gateway overview](</docs/en/gateways>): what a gateway is and how to choose between Claude apps gateway and another product * [Other LLM gateways](</docs/en/llm-gateway>): how to roll out a gateway your organization runs and how it interacts with claude.ai subscriptions - * [Roll out an LLM gateway for your organization](</docs/en/llm-gateway-rollout>): the admin checklist that uses this contract + * [Roll out an LLM gateway for your organization](</docs/en/llm-gateway-rollout>): the admin checklist that uses this guide * [Connect Claude Code to an LLM gateway](</docs/en/llm-gateway-connect>): per-developer configuration and the troubleshooting table * [Beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>): the current set of `anthropic-beta` values * [Messages API](<https://platform.claude.com/docs/en/api/messages>): the API format an Anthropic-format gateway implements
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -207,7 +207,7 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). A discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Before v2.1.197, Claude Code didn’t fold explicit IDs into built-in entries, so a discovered ID such as `claude-sonnet-5` added its own “From gateway” row alongside the `sonnet` row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when the discovered and existing IDs are spellings of the same [Fable](</docs/en/model-config#work-with-fable>) version. A discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Before v2.1.197, Claude Code didn’t fold explicit IDs into built-in entries, so a discovered ID such as `claude-sonnet-5` added its own “From gateway” row alongside the `sonnet` row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. ##
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -54,7 +54,7 @@ Streaming -Inference responses must stream. Claude Code consumes server-sent events as they arrive, so a gateway that buffers complete responses before relaying them stalls the client. Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. An upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, leaves those pauses with nothing to forward. When translating from such an upstream, emit your own `ping` events during silent gaps. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). +Stream inference responses. Claude Code reads the stream as it arrives, so if your gateway buffers complete responses before relaying them, Claude Code stalls. When the client speaks the Amazon Bedrock format, relay the `InvokeModelWithResponseStream` response body and its `Content-Type: application/vnd.amazon.eventstream` header unmodified, and don’t convert the stream to server-sent events. See [Streaming errors behind a gateway or proxy](</docs/en/amazon-bedrock#streaming-errors-behind-a-gateway-or-proxy>). Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. An upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, leaves those pauses with nothing to forward. When translating from such an upstream, emit your own `ping` events during silent gaps. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -133,6 +133,7 @@ [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together +[Prompt caching](</docs/en/prompt-caching>)| No beta pairing. Claude Code attaches `cache_control` markers to `system` blocks and to `messages` entries, including `role: "system"` entries appended mid-conversation| No error: the conversation bills as uncached input on every turn, visible as high `input_tokens` with little or no cache activity in `usage`| Forward `cache_control` unchanged wherever it appears, and don’t convert block-form `system` or message content to plain strings [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to counting context usage through the messages endpoint| Expose the endpoint so token counts don’t consume inference requests The `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` [variables](</docs/en/model-config>) declare model capabilities only in the provider configurations: `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY`, and [`CLAUDE_CODE_USE_MANTLE`](</docs/en/amazon-bedrock#use-the-mantle-endpoint>). They have no effect behind an `ANTHROPIC_BASE_URL` gateway. @@ -143,7 +144,7 @@ Automatic retry and error forwarding -Claude Code retries automatically after some upstream rejections and disables the rejected capability for the rest of the conversation. Rejections of the `thinking` field, of [thinking signatures](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), and of mid-conversation system messages all recover this way. Context management and tool schema field rejections don’t retry; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. +When the upstream rejects the `thinking` field, a [thinking signature](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), a mid-conversation system message, or the `cache_control` marker on one of those messages, Claude Code retries the request and disables the rejected capability for the rest of the conversation. Claude Code doesn’t retry context management or tool schema field rejections; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. ### @@ -184,12 +185,12 @@ Request and response -The request is `GET /v1/models?limit=1000` with a 3-second timeout, and any redirect is treated as failure so the credential can’t leak to a redirect target. A gateway that responds slowly or redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. The discovery request sends exactly one credential header: - - * `ANTHROPIC_AUTH_TOKEN` as a bearer token, when set - * Otherwise the resolved API key, including an [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value, in the `x-api-key` header - -This differs from inference requests, which send a helper value in both headers. A gateway that authenticates `/v1/models` must accept `x-api-key` for helper deployments. Any headers from `ANTHROPIC_CUSTOM_HEADERS` are included as well. Claude Code reads `id` and the optional `display_name` from each entry in the response’s `data` array: +The request is `GET /v1/models?limit=1000` with a 3-second timeout, and any redirect is treated as failure so the credential can’t leak to a redirect target. A gateway that responds slowly or redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. Claude Code sends the discovery request with both credential headers below and omits a header whose value doesn’t resolve. Sending both headers requires Claude Code v2.1.248 or later. Earlier versions send only `Authorization` when `ANTHROPIC_AUTH_TOKEN` is set and only `x-api-key` otherwise. + + * `Authorization`: `ANTHROPIC_AUTH_TOKEN` as a bearer token, otherwise the [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value as a bearer token. In that case Claude Code waits for the helper to return before sending the request. + * `x-api-key`: the API key Claude Code resolved, such as `ANTHROPIC_API_KEY`. When a helper value is the only credential, this header carries it too, so the value arrives in both headers. + +Claude Code also sends any headers from `ANTHROPIC_CUSTOM_HEADERS`. When neither credential header’s value resolves, Claude Code skips discovery and writes a `[gatewayDiscovery] skipped` line to the debug log of a `claude --debug` session. Claude Code reads `id` and the optional `display_name` from each entry in the response’s `data` array: { "data": [
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -164,7 +164,7 @@ Model discovery -When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key don’t surface every model the key can access to every user. +When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. If you or your administrator set `replaceBuiltInOptions` in a [`modelPicker`](</docs/en/settings-reference#modelpicker>) lineup, Claude Code hides the discovered models from the picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key don’t surface every model the key can access to every user. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -24,7 +24,7 @@ API formats -A gateway must expose at least one of the following API formats to Claude Code clients. Which format Claude Code speaks is determined by the client’s configuration: the variable in the Selected by column of the table below points Claude Code at your gateway in that format. Google Cloud’s Agent Platform is Google Cloud’s Claude endpoint, formerly Vertex AI; its variable names keep the `VERTEX` spelling. +A gateway must expose at least one of the following API formats to Claude Code clients. A client picks a format and points Claude Code at your gateway with the variables in the Selected by column of the table below. Google Cloud’s Agent Platform is Google Cloud’s Claude endpoint, formerly Vertex AI; its variable names keep the `VERTEX` spelling. Format| Selected by| Endpoints| Forward unchanged ---|---|---|--- @@ -143,7 +143,7 @@ Automatic retry and error forwarding -Claude Code retries automatically after some upstream rejections and disables the rejected capability for the rest of the conversation. Rejections of the `thinking` field, of [thinking signatures](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), and of mid-conversation system messages all recover this way. Context management and tool schema field rejections don’t retry; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path even when it preserves the status code. +Claude Code retries automatically after some upstream rejections and disables the rejected capability for the rest of the conversation. Rejections of the `thinking` field, of [thinking signatures](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), and of mid-conversation system messages all recover this way. Context management and tool schema field rejections don’t retry; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path, even when it preserves the status code, unless the envelope’s message carries a stable `capability_rejected:` token. [Claude apps gateway substitutes those tokens for cloud providers’ error wording](</docs/en/claude-apps-gateway-config#upstream-error-messages>), for example `capability_rejected: prompt_too_long`. ### @@ -151,7 +151,7 @@ Disable pre-release capabilities -`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. The variable doesn’t affect adaptive reasoning, which is selected by model rather than by beta. It never suppresses the OAuth capability that subscription authentication requires. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/settings#settings-files>). What Claude Code sends with that override in place depends on how you connect: +`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. The variable doesn’t affect adaptive reasoning, which is selected by model rather than by beta. It never suppresses the OAuth capability that subscription authentication requires. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/managed-settings>). What Claude Code sends with that override in place depends on how you connect: * On a direct connection, or through a gateway set with `ANTHROPIC_BASE_URL`, Claude Code keeps sending the tool-search beta header, `defer_loading` tool fields, and `tool_reference` blocks, and strips the rest * On a cloud provider, or signed in through a [Claude apps gateway](</docs/en/claude-apps-gateway>), the override has no effect @@ -206,7 +206,7 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). A discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Before v2.1.197, Claude Code didn’t fold explicit IDs into built-in entries, so a discovered ID such as `claude-sonnet-5` added its own “From gateway” row alongside the `sonnet` row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings-reference#availablemodels>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). A discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Before v2.1.197, Claude Code didn’t fold explicit IDs into built-in entries, so a discovered ID such as `claude-sonnet-5` added its own “From gateway” row alongside the `sonnet` row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. ##
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -108,7 +108,7 @@ * Keep the block in its own array entry: the endpoint treats a merged block that starts with the attribution header as attribution in its entirety and drops everything merged into it, including the rest of the system prompt. * If your gateway must reshape system content, set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) so Claude Code omits the block. Anthropic and the cloud providers’ Claude endpoints read the block for attribution, so omit it at the client rather than stripping or moving it in the gateway. -Requests that reach the endpoint unmodified are unaffected. The variable exists for gateway and third-party caching compatibility, not as a privacy control: on a direct connection the full request already goes to the Anthropic API either way. When both of these hold, Claude Code keeps the block on [auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) classifier requests even when you set the variable to `0`: +The variable exists for gateway and third-party caching compatibility, not as a privacy control: on a direct connection the full request already goes to the Anthropic API either way. When both of these hold, Claude Code keeps the block on [auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) classifier requests even when you set the variable to `0`: * The requests go to `api.anthropic.com`, with `ANTHROPIC_BASE_URL` unset or naming that host and no third-party provider selected. * The active credential isn’t an [Anthropic profile or federation credential](</docs/en/authentication#anthropic-profiles-and-federation-credentials>).
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -54,7 +54,7 @@ Streaming -Inference responses must stream. Claude Code consumes server-sent events as they arrive, so a gateway that buffers complete responses before relaying them stalls the client. Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). +Inference responses must stream. Claude Code consumes server-sent events as they arrive, so a gateway that buffers complete responses before relaying them stalls the client. Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. An upstream that sends no pings at all, such as Amazon Bedrock’s binary event-stream, leaves those pauses with nothing to forward. When translating from such an upstream, emit your own `ping` events during silent gaps. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). ### @@ -108,7 +108,12 @@ * Keep the block in its own array entry: the endpoint treats a merged block that starts with the attribution header as attribution in its entirety and drops everything merged into it, including the rest of the system prompt. * If your gateway must reshape system content, set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) so Claude Code omits the block. Anthropic and the cloud providers’ Claude endpoints read the block for attribution, so omit it at the client rather than stripping or moving it in the gateway. -Requests that reach the endpoint unmodified are unaffected. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it, and any provider your gateway forwards to receives a stable prompt prefix. Before v2.1.181 the block included a per-request token that changed the start of the system prompt on every request. On those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` when your gateway does either of these: +Requests that reach the endpoint unmodified are unaffected. The variable exists for gateway and third-party caching compatibility, not as a privacy control: on a direct connection the full request already goes to the Anthropic API either way. When both of these hold, Claude Code keeps the block on [auto mode](</docs/en/permission-modes#eliminate-prompts-with-auto-mode>) classifier requests even when you set the variable to `0`: + + * The requests go to `api.anthropic.com`, with `ANTHROPIC_BASE_URL` unset or naming that host and no third-party provider selected. + * The active credential isn’t an [Anthropic profile or federation credential](</docs/en/authentication#anthropic-profiles-and-federation-credentials>). + +Classifier requests skip the rest of Claude Code’s system prompt, so on those requests the block is the only marker in the request body that identifies them as Claude Code traffic. When either condition fails, through an LLM gateway, on a third-party provider, or with a profile or federation credential active, setting `0` removes the block from classifier requests too. Before v2.1.229, this exception didn’t exist: setting `0` removed the block from those classifier requests, and when the API declined the unidentified requests, auto mode failed on every action it sent to the classifier. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it, and any provider your gateway forwards to receives a stable prompt prefix. Before v2.1.181 the block included a per-request token that changed the start of the system prompt on every request. On those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` when your gateway does either of these: * Implements a prompt cache keyed on the request body. * Forwards requests to a third-party provider such as Amazon Bedrock, Microsoft Foundry, or Google Cloud’s Agent Platform, in the Anthropic Messages format or the provider’s own, where the changing prefix reduces prompt-cache reuse on that provider.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -146,7 +146,12 @@ Disable pre-release capabilities -`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. It doesn’t affect adaptive reasoning, which is selected by model rather than by beta, and it never suppresses the OAuth capability that subscription authentication requires. The set of capabilities Claude Code sends grows over releases. For current beta header strings, see the [beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>); test your gateway against new Claude Code releases rather than pinning to an observed list. +`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. The variable doesn’t affect adaptive reasoning, which is selected by model rather than by beta. It never suppresses the OAuth capability that subscription authentication requires. On Claude Code v2.1.227 or later, your organization can keep [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) on under this variable through [managed settings](</docs/en/settings#settings-files>). What Claude Code sends with that override in place depends on how you connect: + + * On a direct connection, or through a gateway set with `ANTHROPIC_BASE_URL`, Claude Code keeps sending the tool-search beta header, `defer_loading` tool fields, and `tool_reference` blocks, and strips the rest + * On a cloud provider, or signed in through a [Claude apps gateway](</docs/en/claude-apps-gateway>), the override has no effect + +The set of capabilities Claude Code sends grows over releases. For current beta header strings, see the [beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>); test your gateway against new Claude Code releases rather than pinning to an observed list. ## @@ -196,7 +201,7 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). As of Claude Code v2.1.197, a discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). A discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Before v2.1.197, Claude Code didn’t fold explicit IDs into built-in entries, so a discovered ID such as `claude-sonnet-5` added its own “From gateway” row alongside the `sonnet` row. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. ##
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -46,7 +46,7 @@ Optional endpoints and startup traffic -Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. +Token-counting endpoints are the only optional ones: when they’re absent, Claude Code falls back to counting context usage through the inference endpoint instead. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. ### @@ -128,7 +128,7 @@ [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together -[Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to estimating context usage locally| Expose the endpoint if you want exact counts +[Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to counting context usage through the messages endpoint| Expose the endpoint so token counts don’t consume inference requests The `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` [variables](</docs/en/model-config>) declare model capabilities only in the provider configurations: `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY`, and [`CLAUDE_CODE_USE_MANTLE`](</docs/en/amazon-bedrock#use-the-mantle-endpoint>). They have no effect behind an `ANTHROPIC_BASE_URL` gateway.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -29,7 +29,7 @@ Format| Selected by| Endpoints| Forward unchanged ---|---|---|--- Anthropic Messages| `ANTHROPIC_BASE_URL`| `/v1/messages`, `/v1/messages/count_tokens` (optional)| `anthropic-beta` and `anthropic-version` request headers -Amazon Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`| `anthropic_beta` and `anthropic_version` request body fields +Amazon Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`, `/model/{model}/count-tokens` (optional)| `anthropic_beta` and `anthropic_version` request body fields Google Cloud’s Agent Platform rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field ### @@ -46,7 +46,7 @@ Optional endpoints and startup traffic -Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Amazon Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. +Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything. An Anthropic Messages-format gateway receives a `HEAD /api/hello` connection-warming probe, which Claude Code skips when an HTTP proxy or client certificate is configured. An Amazon Bedrock-format gateway receives a `GET /inference-profiles?type=SYSTEM_DEFINED` request and, when the configured model is an inference profile, `GET /inference-profiles/{profile}` lookups. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. ### @@ -154,7 +154,7 @@ Model discovery -When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key don’t surface every model the key can access to every user. This requires Claude Code v2.1.129 or later. +When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key don’t surface every model the key can access to every user. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -179,7 +179,7 @@ * `ANTHROPIC_AUTH_TOKEN` as a bearer token, when set * Otherwise the resolved API key, including an [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value, in the `x-api-key` header -This differs from inference requests, which send a helper value in both headers. A gateway that authenticates `/v1/models` must accept `x-api-key` for helper deployments. Any headers from `ANTHROPIC_CUSTOM_HEADERS` are included as well. Claude Code reads `id` and the optional `display_name` from each entry in the response’s `data` array, and ignores entries whose `id` doesn’t begin with `claude` or `anthropic`: +This differs from inference requests, which send a helper value in both headers. A gateway that authenticates `/v1/models` must accept `x-api-key` for helper deployments. Any headers from `ANTHROPIC_CUSTOM_HEADERS` are included as well. Claude Code reads `id` and the optional `display_name` from each entry in the response’s `data` array: { "data": [ @@ -188,6 +188,8 @@ ] } +Claude Code keeps an entry when its `id` contains `claude` or `anthropic` anywhere in the string, matched case-insensitively, and ignores the rest. Provider-prefixed IDs such as `vertex_ai/claude-sonnet-4-6` or `bedrock/anthropic.claude-sonnet-4-5` pass the filter; an ID that contains neither substring doesn’t. Before v2.1.223, Claude Code kept an entry only when its `id` began with `claude` or `anthropic`, which hid provider-prefixed IDs. + ### ​
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -54,7 +54,7 @@ Streaming -Inference responses must stream. Claude Code consumes server-sent events as they arrive, so a gateway that buffers complete responses before relaying them stalls the client. +Inference responses must stream. Claude Code consumes server-sent events as they arrive, so a gateway that buffers complete responses before relaying them stalls the client. Forward keep-alive pings as well. On connections through `ANTHROPIC_BASE_URL` or `ANTHROPIC_AWS_BASE_URL`, Claude Code counts every byte your gateway relays, including SSE `ping` events and comment lines, and aborts a stream that goes silent for 300 seconds by default. The upstream’s pings are the only traffic during long thinking pauses, so if your gateway strips or buffers them, Claude Code aborts the stream during those pauses; [Automatic retries](</docs/en/errors#automatic-retries>) covers what an aborted stream reports based on how far the response had progressed. Gateways reached through `ANTHROPIC_BEDROCK_BASE_URL`, `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_FOUNDRY_BASE_URL` aren’t wrapped by this byte-level watchdog, even when they relay the Anthropic Messages format; there, a [5-minute idle timeout](</docs/en/env-vars>) aborts a silent stream instead, and on `ANTHROPIC_BEDROCK_BASE_URL` connections you can add the byte watchdog with [`CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK`](</docs/en/env-vars>). ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -108,7 +108,10 @@ * Keep the block in its own array entry: the endpoint treats a merged block that starts with the attribution header as attribution in its entirety and drops everything merged into it, including the rest of the system prompt. * If your gateway must reshape system content, set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) so Claude Code omits the block. Anthropic and the cloud providers’ Claude endpoints read the block for attribution, so omit it at the client rather than stripping or moving it in the gateway. -Requests that reach the endpoint unmodified are unaffected. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it. Before v2.1.181 the block included a per-request token; on those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` if your gateway implements such a cache. +Requests that reach the endpoint unmodified are unaffected. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it, and any provider your gateway forwards to receives a stable prompt prefix. Before v2.1.181 the block included a per-request token that changed the start of the system prompt on every request. On those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` when your gateway does either of these: + + * Implements a prompt cache keyed on the request body. + * Forwards requests to a third-party provider such as Amazon Bedrock, Microsoft Foundry, or Google Cloud’s Agent Platform, in the Anthropic Messages format or the provider’s own, where the changing prefix reduces prompt-cache reuse on that provider. ## @@ -191,7 +194,7 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). As of Claude Code v2.1.197, a discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). As of Claude Code v2.1.197, a discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If you set [`CLAUDE_CONFIG_DIR`](</docs/en/env-vars>), the cache lives under that directory instead. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. ##
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -46,7 +46,7 @@ Optional endpoints and startup traffic -Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Amazon Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. +Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Amazon Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. The [fast mode](</docs/en/fast-mode>) availability check never appears in gateway logs: it calls `api.anthropic.com` directly rather than following `ANTHROPIC_BASE_URL`, so on a network that blocks direct egress to `api.anthropic.com`, fast mode can report a connectivity error while inference through the gateway keeps working. The [WebFetch domain safety check](</docs/en/data-usage#webfetch-domain-safety-check>) also calls `api.anthropic.com` directly. [Use fast mode behind proxies and LLM gateways](</docs/en/fast-mode#use-fast-mode-behind-proxies-and-llm-gateways>) covers the variables that restore it. ###
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -121,7 +121,7 @@ Feature| Header and body pair| Symptom when broken| Remediation ---|---|---|--- [Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude 4.6 and later, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead -[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-management>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) +[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-editing>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -122,7 +122,7 @@ ---|---|---|--- [Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude 4.6 and later, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead [Context management](<https://platform.claude.com/docs/en/build-with-claude/context-management>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) -[Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#1m-token-context-window>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim +[Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#context-window-sizes-by-model>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` [Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to estimating context usage locally| Expose the endpoint if you want exact counts
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -24,13 +24,13 @@ API formats -A gateway must expose at least one of the following API formats to Claude Code clients. Which format Claude Code speaks is determined by the client’s configuration: the variable in the Selected by column of the table below points Claude Code at your gateway in that format. Agent Platform is Google Cloud’s Claude endpoint, formerly Vertex AI; its variable names keep the `VERTEX` spelling. +A gateway must expose at least one of the following API formats to Claude Code clients. Which format Claude Code speaks is determined by the client’s configuration: the variable in the Selected by column of the table below points Claude Code at your gateway in that format. Google Cloud’s Agent Platform is Google Cloud’s Claude endpoint, formerly Vertex AI; its variable names keep the `VERTEX` spelling. Format| Selected by| Endpoints| Forward unchanged ---|---|---|--- Anthropic Messages| `ANTHROPIC_BASE_URL`| `/v1/messages`, `/v1/messages/count_tokens` (optional)| `anthropic-beta` and `anthropic-version` request headers -Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`| `anthropic_beta` and `anthropic_version` request body fields -Agent Platform rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field +Amazon Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`| `anthropic_beta` and `anthropic_version` request body fields +Google Cloud’s Agent Platform rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field ### @@ -46,7 +46,7 @@ Optional endpoints and startup traffic -Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. +Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Google Cloud’s Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Amazon Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. ### @@ -64,8 +64,8 @@ Which format the client speaks determines what your gateway receives. The common failure mode is a mismatch between the format the client sends to your gateway and the format the upstream provider behind it accepts. - * When the client speaks the Bedrock or Agent Platform format, Claude Code sends only the subset of its full capability set that those providers accept - * When the client speaks the Anthropic Messages format, Claude Code sends the full set, even if your gateway forwards to a Bedrock or Agent Platform upstream + * When the client speaks the Amazon Bedrock or Google Cloud’s Agent Platform format, Claude Code sends only the subset of its full capability set that those providers accept + * When the client speaks the Anthropic Messages format, Claude Code sends the full set, even if your gateway forwards to an Amazon Bedrock or Google Cloud’s Agent Platform upstream Bridging that difference is your gateway’s job. Feature pass-through describes what breaks when it doesn’t. @@ -80,7 +80,7 @@ Header| Description ---|--- `Authorization`, `x-api-key`| The developer’s gateway credential, in one or both headers depending on which [credential variable](</docs/en/llm-gateway-connect#set-the-credential-variable>) they set -`anthropic-version`| API version, currently `2023-06-01`. Bedrock- and Agent Platform-format requests also carry the `anthropic_version` body field, whose value is the provider dialect string, not this header’s value +`anthropic-version`| API version, currently `2023-06-01`. Amazon Bedrock- and Google Cloud’s Agent Platform-format requests also carry the `anthropic_version` body field, whose value is the provider dialect string, not this header’s value `anthropic-beta`| Comma-separated capability values for the request. Forward the header verbatim; don’t allowlist individual values, because the set changes with Claude Code releases. When the developer authenticates with a claude.ai login, which is possible when `ANTHROPIC_BASE_URL` is set without a gateway credential variable, this header also carries an OAuth capability that the upstream requires, and stripping it fails those requests with `401` `x-claude-code-session-id`| A unique identifier for the current Claude Code session. Use it to aggregate all requests from one session without parsing request bodies `x-claude-code-agent-id`| Identifier of the [subagent](</docs/en/sub-agents>) that issued the request, present only on requests from an agent Claude Code spawned inside the session. Use it with the session ID to attribute cost to parallel agents @@ -94,7 +94,7 @@ Forward as open lists -Treat the headers and body fields as open lists, not closed ones. Claude Code gains capabilities over releases, and they arrive as new `anthropic-beta` values, new request body fields, and occasionally new `anthropic-*` or `x-claude-code-*` headers. When forwarding to an Anthropic-format upstream, pass `anthropic-*` request headers and request body fields through unchanged rather than allowlisting the ones you see today. A gateway pinned to an observed list strips the next capability’s header or field and breaks it on the release that introduces it. The exception is a non-Anthropic upstream such as Bedrock or Agent Platform, where bridging the schema difference is the gateway’s job; see feature pass-through. +Treat the headers and body fields as open lists, not closed ones. Claude Code gains capabilities over releases, and they arrive as new `anthropic-beta` values, new request body fields, and occasionally new `anthropic-*` or `x-claude-code-*` headers. When forwarding to an Anthropic-format upstream, pass `anthropic-*` request headers and request body fields through unchanged rather than allowlisting the ones you see today. A gateway pinned to an observed list strips the next capability’s header or field and breaks it on the release that introduces it. The exception is a non-Anthropic upstream such as Amazon Bedrock or Google Cloud’s Agent Platform, where bridging the schema difference is the gateway’s job; see feature pass-through. ## @@ -102,7 +102,13 @@ System prompt attribution block -Claude Code prepends a short attribution block to the system prompt containing the client version and a fingerprint derived from the conversation. The `api.anthropic.com` endpoint strips the block before processing, so it doesn’t affect first-party prompt caching; any other upstream receives it as part of the prompt. Anthropic and the cloud providers’ Claude endpoints read it for attribution, so to omit it set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) rather than stripping it in the gateway. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it. Before v2.1.181 the block included a per-request token; on those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` if your gateway implements such a cache. +Claude Code prepends a short attribution block to the system prompt containing the client version and a fingerprint derived from the conversation. The `api.anthropic.com` endpoint strips the block before processing when it arrives unchanged as the first system block, so it doesn’t affect first-party prompt caching. Any other upstream receives it as part of the prompt. The strip is positional, so it only works when the gateway forwards the `system` array unchanged. To keep the block out of the prompt without losing other system content: + + * Forward the `system` array exactly as received, keeping the block first: prepending another system block, reordering the array, or converting it to a single string defeats the strip, and the block then reaches the model and the prompt cache key. + * Keep the block in its own array entry: the endpoint treats a merged block that starts with the attribution header as attribution in its entirety and drops everything merged into it, including the rest of the system prompt. + * If your gateway must reshape system content, set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) so Claude Code omits the block. Anthropic and the cloud providers’ Claude endpoints read the block for attribution, so omit it at the client rather than stripping or moving it in the gateway. + +Requests that reach the endpoint unmodified are unaffected. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it. Before v2.1.181 the block included a per-request token; on those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` if your gateway implements such a cache. ## @@ -115,10 +121,10 @@ Feature| Header and body pair| Symptom when broken| Remediation ---|---|---|--- [Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude 4.6 and later, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead -[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-management>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) +[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-management>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Amazon Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#1m-token-context-window>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` -[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Bedrock and Agent Platform upstreams| Forward the field and its headers together +[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Amazon Bedrock and Google Cloud’s Agent Platform upstreams| Forward the field and its headers together [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to estimating context usage locally| Expose the endpoint if you want exact counts The `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` [variables](</docs/en/model-config>) declare model capabilities only in the provider configurations: `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY`, and [`CLAUDE_CODE_USE_MANTLE`](</docs/en/amazon-bedrock#use-the-mantle-endpoint>). They have no effect behind an `ANTHROPIC_BASE_URL` gateway.
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -185,7 +185,7 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped only when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). Built-in rows are keyed on aliases such as `sonnet`, so a discovered ID such as `claude-sonnet-4-6` adds its own “From gateway” row alongside the built-in entry rather than replacing it. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). As of Claude Code v2.1.197, a discovered explicit ID is also folded into a built-in entry when both resolve to the same model. Built-in rows are keyed on aliases such as `sonnet`, so a discovered explicit ID of the model the alias currently resolves to, such as `claude-sonnet-5`, collapses into the `sonnet` row, while an ID the alias doesn’t resolve to, such as `claude-sonnet-4-6`, still adds its own “From gateway” row alongside the built-in entry. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. ##
modified
Show diff (161 lines)
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -1,4 +1,4 @@ -This page documents the requests Claude Code sends to a gateway, including the endpoints it calls, the headers and body fields the gateway must forward, and which features stop working when it doesn’t. It is written for operators configuring a gateway product to work with Claude Code. +This page documents the requests Claude Code sends to a gateway, including the endpoints it calls, the headers and body fields the gateway must forward, and which features stop working when it doesn’t. It is written for operators configuring a gateway product to work with Claude Code. A running [Claude apps gateway](</docs/en/claude-apps-gateway>) serves a machine-readable version of this contract at `GET /protocol`, covering the same forwarding requirements plus the Claude apps gateway-specific endpoints for SSO sign-in, managed-settings delivery, and telemetry. Claude apps gateway runs from the same `claude` binary as the CLI, so the [Claude apps gateway quickstart](</docs/en/claude-apps-gateway#quickstart>) is the shortest path to a running instance you can fetch the spec from. * To roll out an existing or third-party gateway for your organization, see [Roll out an LLM gateway](</docs/en/llm-gateway-rollout>) * If you’re an individual developer authenticating Claude Code to a gateway with a credential you were given, see [Connect Claude Code to an LLM gateway](</docs/en/llm-gateway-connect>) @@ -24,13 +24,13 @@ API formats -A gateway must expose at least one of the following API formats to Claude Code clients. Which format Claude Code speaks is determined by the client’s configuration: the variable in the Selected by column of the table below points Claude Code at your gateway in that format. +A gateway must expose at least one of the following API formats to Claude Code clients. Which format Claude Code speaks is determined by the client’s configuration: the variable in the Selected by column of the table below points Claude Code at your gateway in that format. Agent Platform is Google Cloud’s Claude endpoint, formerly Vertex AI; its variable names keep the `VERTEX` spelling. Format| Selected by| Endpoints| Forward unchanged ---|---|---|--- Anthropic Messages| `ANTHROPIC_BASE_URL`| `/v1/messages`, `/v1/messages/count_tokens` (optional)| `anthropic-beta` and `anthropic-version` request headers Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`| `anthropic_beta` and `anthropic_version` request body fields -Vertex rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field +Agent Platform rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field ### @@ -46,7 +46,7 @@ Optional endpoints and startup traffic -Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Vertex method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. +Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Agent Platform method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. ### @@ -64,8 +64,8 @@ Which format the client speaks determines what your gateway receives. The common failure mode is a mismatch between the format the client sends to your gateway and the format the upstream provider behind it accepts. - * When the client speaks the Bedrock or Vertex format, Claude Code sends only the subset of its full capability set that those providers accept - * When the client speaks the Anthropic Messages format, Claude Code sends the full set, even if your gateway forwards to a Bedrock or Vertex upstream + * When the client speaks the Bedrock or Agent Platform format, Claude Code sends only the subset of its full capability set that those providers accept + * When the client speaks the Anthropic Messages format, Claude Code sends the full set, even if your gateway forwards to a Bedrock or Agent Platform upstream Bridging that difference is your gateway’s job. Feature pass-through describes what breaks when it doesn’t. @@ -80,13 +80,13 @@ Header| Description ---|--- `Authorization`, `x-api-key`| The developer’s gateway credential, in one or both headers depending on which [credential variable](</docs/en/llm-gateway-connect#set-the-credential-variable>) they set -`anthropic-version`| API version, currently `2023-06-01`. Bedrock- and Vertex-format requests also carry the `anthropic_version` body field, whose value is the provider dialect string, not this header’s value -`anthropic-beta`| Comma-separated capability values for the request. Forward the header verbatim; do not allowlist individual values, because the set changes with Claude Code releases. When the developer authenticates with a claude.ai login, which is possible when `ANTHROPIC_BASE_URL` is set without a gateway credential variable, this header also carries an OAuth capability that the upstream requires, and stripping it fails those requests with `401` +`anthropic-version`| API version, currently `2023-06-01`. Bedrock- and Agent Platform-format requests also carry the `anthropic_version` body field, whose value is the provider dialect string, not this header’s value +`anthropic-beta`| Comma-separated capability values for the request. Forward the header verbatim; don’t allowlist individual values, because the set changes with Claude Code releases. When the developer authenticates with a claude.ai login, which is possible when `ANTHROPIC_BASE_URL` is set without a gateway credential variable, this header also carries an OAuth capability that the upstream requires, and stripping it fails those requests with `401` `x-claude-code-session-id`| A unique identifier for the current Claude Code session. Use it to aggregate all requests from one session without parsing request bodies `x-claude-code-agent-id`| Identifier of the [subagent](</docs/en/sub-agents>) that issued the request, present only on requests from an agent Claude Code spawned inside the session. Use it with the session ID to attribute cost to parallel agents `x-claude-code-parent-agent-id`| Identifier of the agent that spawned the requesting agent, present only for nested agents -Subagent IDs are generated fresh for each spawn. Teammate agents, the named members of an [agent team](</docs/en/agent-teams>), reuse a stable name-based ID across reconnections. In both cases the ID identifies an agent, not a person or a device, so do not treat the agent ID header as a user identifier. If your developers set `ANTHROPIC_CUSTOM_HEADERS`, those headers appear on requests as well. +Subagent IDs are generated fresh for each spawn. Teammate agents, the named members of an [agent team](</docs/en/agent-teams>), reuse a stable name-based ID across reconnections. In both cases the ID identifies an agent, not a person or a device, so don’t treat the agent ID header as a user identifier. If your developers set `ANTHROPIC_CUSTOM_HEADERS`, those headers appear on requests as well. ### @@ -94,7 +94,7 @@ Forward as open lists -Treat the headers and body fields as open lists, not closed ones. Claude Code gains capabilities over releases, and they arrive as new `anthropic-beta` values, new request body fields, and occasionally new `anthropic-*` or `x-claude-code-*` headers. When forwarding to an Anthropic-format upstream, pass `anthropic-*` request headers and request body fields through unchanged rather than allowlisting the ones you see today. A gateway pinned to an observed list strips the next capability’s header or field and breaks it on the release that introduces it. The exception is a non-Anthropic upstream such as Bedrock or Vertex, where bridging the schema difference is the gateway’s job; see feature pass-through. +Treat the headers and body fields as open lists, not closed ones. Claude Code gains capabilities over releases, and they arrive as new `anthropic-beta` values, new request body fields, and occasionally new `anthropic-*` or `x-claude-code-*` headers. When forwarding to an Anthropic-format upstream, pass `anthropic-*` request headers and request body fields through unchanged rather than allowlisting the ones you see today. A gateway pinned to an observed list strips the next capability’s header or field and breaks it on the release that introduces it. The exception is a non-Anthropic upstream such as Bedrock or Agent Platform, where bridging the schema difference is the gateway’s job; see feature pass-through. ## @@ -102,7 +102,7 @@ System prompt attribution block -Claude Code prepends a short attribution block to the system prompt containing the client version and a fingerprint derived from the conversation. The `api.anthropic.com` endpoint strips the block before processing, so it does not affect first-party prompt caching; any other upstream receives it as part of the prompt. Anthropic and the cloud providers’ Claude endpoints read it for attribution, so to omit it set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) rather than stripping it in the gateway. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it. Before v2.1.181 the block included a per-request token; on those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` if your gateway implements such a cache. +Claude Code prepends a short attribution block to the system prompt containing the client version and a fingerprint derived from the conversation. The `api.anthropic.com` endpoint strips the block before processing, so it doesn’t affect first-party prompt caching; any other upstream receives it as part of the prompt. Anthropic and the cloud providers’ Claude endpoints read it for attribution, so to omit it set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) rather than stripping it in the gateway. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it. Before v2.1.181 the block included a per-request token; on those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` if your gateway implements such a cache. ## @@ -110,7 +110,7 @@ Feature pass-through -Claude Code treats an `ANTHROPIC_BASE_URL` gateway as an Anthropic-format endpoint and sends it the beta headers and request body fields it sends to `api.anthropic.com`, except a small set of diagnostics and defaults reserved for direct connections. Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces hard `400` errors; only when both halves are absent together does the feature turn off quietly. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. Fine-grained tool streaming is one of the direct-connection defaults: it is off by default whenever requests route through a custom base URL, and a gateway receives it when developers set [`CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING=1`](</docs/en/env-vars>). +Claude Code treats an `ANTHROPIC_BASE_URL` gateway as an Anthropic-format endpoint and sends it the beta headers and request body fields it sends to `api.anthropic.com`, except a small set of diagnostics and defaults reserved for direct connections, such as the fine-grained tool streaming default covered below. That set varies by release, so don’t depend on its contents. Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces hard `400` errors; only when both halves are absent together does the feature turn off quietly. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. Fine-grained tool streaming is one of the direct-connection defaults: it is off by default whenever requests route through a custom base URL, and a gateway receives it when developers set [`CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING=1`](</docs/en/env-vars>). Feature| Header and body pair| Symptom when broken| Remediation ---|---|---|--- @@ -118,7 +118,7 @@ [Context management](<https://platform.claude.com/docs/en/build-with-claude/context-management>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) [Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#1m-token-context-window>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` -[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Bedrock and Vertex upstreams| Forward the field and its headers together +[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Bedrock and Agent Platform upstreams| Forward the field and its headers together [Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to estimating context usage locally| Expose the endpoint if you want exact counts The `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` [variables](</docs/en/model-config>) declare model capabilities only in the provider configurations: `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY`, and [`CLAUDE_CODE_USE_MANTLE`](</docs/en/amazon-bedrock#use-the-mantle-endpoint>). They have no effect behind an `ANTHROPIC_BASE_URL` gateway. @@ -129,7 +129,7 @@ Automatic retry and error forwarding -Claude Code retries automatically after some upstream rejections and disables the rejected capability for the rest of the conversation. Rejections of the `thinking` field, of [thinking signatures](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), and of mid-conversation system messages all recover this way. Context management and tool schema field rejections do not retry; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path even when it preserves the status code. +Claude Code retries automatically after some upstream rejections and disables the rejected capability for the rest of the conversation. Rejections of the `thinking` field, of [thinking signatures](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), and of mid-conversation system messages all recover this way. Context management and tool schema field rejections don’t retry; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path even when it preserves the status code. ### @@ -137,7 +137,7 @@ Disable pre-release capabilities -`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. It does not affect adaptive reasoning, which is selected by model rather than by beta, and it never suppresses the OAuth capability that subscription authentication requires. The set of capabilities Claude Code sends grows over releases. For current beta header strings, see the [beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>); test your gateway against new Claude Code releases rather than pinning to an observed list. +`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. It doesn’t affect adaptive reasoning, which is selected by model rather than by beta, and it never suppresses the OAuth capability that subscription authentication requires. The set of capabilities Claude Code sends grows over releases. For current beta header strings, see the [beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>); test your gateway against new Claude Code releases rather than pinning to an observed list. ## @@ -145,7 +145,7 @@ Model discovery -When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key do not surface every model the key can access to every user. This requires Claude Code v2.1.129 or later. +When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key don’t surface every model the key can access to every user. This requires Claude Code v2.1.129 or later. ### @@ -153,7 +153,7 @@ When discovery runs -Discovery applies only to the Anthropic Messages format. It does not run when: +Discovery applies only to the Anthropic Messages format. It doesn’t run when: * Any `CLAUDE_CODE_USE_*` provider variable is set, even if `ANTHROPIC_BASE_URL` is also set * `ANTHROPIC_BASE_URL` is unset or points at `api.anthropic.com` @@ -165,7 +165,7 @@ Request and response -The request is `GET /v1/models?limit=1000` with a 3-second timeout, and any redirect is treated as failure so the credential cannot leak to a redirect target. A gateway that responds slowly or redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. The discovery request sends exactly one credential header: +The request is `GET /v1/models?limit=1000` with a 3-second timeout, and any redirect is treated as failure so the credential can’t leak to a redirect target. A gateway that responds slowly or redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. The discovery request sends exactly one credential header: * `ANTHROPIC_AUTH_TOKEN` as a bearer token, when set * Otherwise the resolved API key, including an [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value, in the `x-api-key` header @@ -185,7 +185,7 @@ Picker entries and caching -The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. A discovered ID is skipped only when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). Built-in rows are keyed on aliases such as `sonnet`, so a discovered ID such as `claude-sonnet-4-6` adds its own “From gateway” row alongside the built-in entry. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If the request fails or the gateway does not implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. A discovered ID is skipped only when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). Built-in rows are keyed on aliases such as `sonnet`, so a discovered ID such as `claude-sonnet-4-6` adds its own “From gateway” row alongside the built-in entry rather than replacing it. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If the request fails or the gateway doesn’t implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. ## @@ -195,7 +195,8 @@ For the rest of the gateway documentation set and the underlying API references: - * [LLM gateways overview](</docs/en/llm-gateway>): what a gateway is and how it interacts with claude.ai subscriptions + * [Gateway overview](</docs/en/gateways>): what a gateway is and how to choose between Claude apps gateway and another product + * [Other LLM gateways](</docs/en/llm-gateway>): how to roll out a gateway your organization runs and how it interacts with claude.ai subscriptions * [Roll out an LLM gateway for your organization](</docs/en/llm-gateway-rollout>): the admin checklist that uses this contract * [Connect Claude Code to an LLM gateway](</docs/en/llm-gateway-connect>): per-developer configuration and the troubleshooting table * [Beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>): the current set of `anthropic-beta` values
modified
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -175,7 +175,7 @@ { "data": [ { "id": "claude-sonnet-4-6", "display_name": "Claude Sonnet 4.6" }, - { "id": "claude-opus-4-7" } + { "id": "claude-opus-4-8" } ] }
added
Show diff (205 lines)
--- a/llm-gateway-protocol.md +++ b/llm-gateway-protocol.md @@ -0,0 +1,202 @@ +This page documents the requests Claude Code sends to a gateway, including the endpoints it calls, the headers and body fields the gateway must forward, and which features stop working when it doesn’t. It is written for operators configuring a gateway product to work with Claude Code. + + * To roll out an existing or third-party gateway for your organization, see [Roll out an LLM gateway](</docs/en/llm-gateway-rollout>) + * If you’re an individual developer authenticating Claude Code to a gateway with a credential you were given, see [Connect Claude Code to an LLM gateway](</docs/en/llm-gateway-connect>) + +This page covers: + + * API formats and the endpoints to serve for each + * Request headers: which must reach the upstream and which your gateway can consume + * The system prompt attribution block and how it interacts with prompt caching + * Feature pass-through: what breaks when headers or body fields are stripped + * Model discovery + +This page uses two terms for what your gateway does with each header and body field: + + * **Forward unchanged** : pass it to the upstream byte-for-byte + * **Consume** : the gateway may read it for routing, attribution, or tracing and need not forward it + +Anything not marked forward unchanged is yours to consume or ignore. + +## + +​ + +API formats + +A gateway must expose at least one of the following API formats to Claude Code clients. Which format Claude Code speaks is determined by the client’s configuration: the variable in the Selected by column of the table below points Claude Code at your gateway in that format. + +Format| Selected by| Endpoints| Forward unchanged +---|---|---|--- +Anthropic Messages| `ANTHROPIC_BASE_URL`| `/v1/messages`, `/v1/messages/count_tokens` (optional)| `anthropic-beta` and `anthropic-version` request headers +Bedrock InvokeModel| `ANTHROPIC_BEDROCK_BASE_URL` with `CLAUDE_CODE_USE_BEDROCK=1`| `/model/{model}/invoke`, `/model/{model}/invoke-with-response-stream`| `anthropic_beta` and `anthropic_version` request body fields +Vertex rawPredict| `ANTHROPIC_VERTEX_BASE_URL` with `CLAUDE_CODE_USE_VERTEX=1`| `:rawPredict`, `:streamRawPredict`, `count-tokens:rawPredict` (optional)| `anthropic-beta` and `anthropic-version` request headers, and the `anthropic_version` request body field + +### + +​ + +Foundry and Claude Platform on AWS + +Microsoft Foundry and the [Claude Platform on AWS](</docs/en/claude-platform-on-aws>) implement the Anthropic Messages format. Claude Code routes to them through their own variables, `ANTHROPIC_FOUNDRY_BASE_URL` and `ANTHROPIC_AWS_BASE_URL`, but a gateway fronting either implements the Anthropic Messages row above. A gateway fronting the Claude Platform on AWS must also forward the `anthropic-workspace-id` header, which [that platform requires on every request](</docs/en/claude-platform-on-aws>). + +### + +​ + +Optional endpoints and startup traffic + +Token-counting endpoints are the only optional ones: when they’re absent, Claude Code estimates context usage locally. Inference requests post to `/v1/messages?beta=true`, so match on the path, not the full URL. The Vertex method suffixes attach to the publisher model path, as in `/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict`. A gateway also sees best-effort startup traffic it can reject without breaking anything: a `HEAD /` connectivity probe, and on Bedrock-format gateways a `GET /inference-profiles?type=SYSTEM_DEFINED` request. + +### + +​ + +Streaming + +Inference responses must stream. Claude Code consumes server-sent events as they arrive, so a gateway that buffers complete responses before relaying them stalls the client. + +### + +​ + +Format mismatch with the upstream + +Which format the client speaks determines what your gateway receives. The common failure mode is a mismatch between the format the client sends to your gateway and the format the upstream provider behind it accepts. + + * When the client speaks the Bedrock or Vertex format, Claude Code sends only the subset of its full capability set that those providers accept + * When the client speaks the Anthropic Messages format, Claude Code sends the full set, even if your gateway forwards to a Bedrock or Vertex upstream + +Bridging that difference is your gateway’s job. Feature pass-through describes what breaks when it doesn’t. + +## + +​ + +Request headers + +Claude Code includes these headers on API requests. Header names are case-insensitive on the wire. Forward `anthropic-version` and `anthropic-beta` unchanged, plus `anthropic-workspace-id` when the upstream is the [Claude Platform on AWS](</docs/en/claude-platform-on-aws>); the rest the gateway may consume for routing, attribution, and tracing, and need not forward. + +Header| Description +---|--- +`Authorization`, `x-api-key`| The developer’s gateway credential, in one or both headers depending on which [credential variable](</docs/en/llm-gateway-connect#set-the-credential-variable>) they set +`anthropic-version`| API version, currently `2023-06-01`. Bedrock- and Vertex-format requests also carry the `anthropic_version` body field, whose value is the provider dialect string, not this header’s value +`anthropic-beta`| Comma-separated capability values for the request. Forward the header verbatim; do not allowlist individual values, because the set changes with Claude Code releases. When the developer authenticates with a claude.ai login, which is possible when `ANTHROPIC_BASE_URL` is set without a gateway credential variable, this header also carries an OAuth capability that the upstream requires, and stripping it fails those requests with `401` +`x-claude-code-session-id`| A unique identifier for the current Claude Code session. Use it to aggregate all requests from one session without parsing request bodies +`x-claude-code-agent-id`| Identifier of the [subagent](</docs/en/sub-agents>) that issued the request, present only on requests from an agent Claude Code spawned inside the session. Use it with the session ID to attribute cost to parallel agents +`x-claude-code-parent-agent-id`| Identifier of the agent that spawned the requesting agent, present only for nested agents + +Subagent IDs are generated fresh for each spawn. Teammate agents, the named members of an [agent team](</docs/en/agent-teams>), reuse a stable name-based ID across reconnections. In both cases the ID identifies an agent, not a person or a device, so do not treat the agent ID header as a user identifier. If your developers set `ANTHROPIC_CUSTOM_HEADERS`, those headers appear on requests as well. + +### + +​ + +Forward as open lists + +Treat the headers and body fields as open lists, not closed ones. Claude Code gains capabilities over releases, and they arrive as new `anthropic-beta` values, new request body fields, and occasionally new `anthropic-*` or `x-claude-code-*` headers. When forwarding to an Anthropic-format upstream, pass `anthropic-*` request headers and request body fields through unchanged rather than allowlisting the ones you see today. A gateway pinned to an observed list strips the next capability’s header or field and breaks it on the release that introduces it. The exception is a non-Anthropic upstream such as Bedrock or Vertex, where bridging the schema difference is the gateway’s job; see feature pass-through. + +## + +​ + +System prompt attribution block + +Claude Code prepends a short attribution block to the system prompt containing the client version and a fingerprint derived from the conversation. The `api.anthropic.com` endpoint strips the block before processing, so it does not affect first-party prompt caching; any other upstream receives it as part of the prompt. Anthropic and the cloud providers’ Claude endpoints read it for attribution, so to omit it set [`CLAUDE_CODE_ATTRIBUTION_HEADER=0`](</docs/en/env-vars>) rather than stripping it in the gateway. From Claude Code v2.1.181, the block is stable for the lifetime of a conversation when requests route through a custom base URL, so a gateway-side prompt cache keyed on the full request body works without disabling it. Before v2.1.181 the block included a per-request token; on those versions, set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` if your gateway implements such a cache. + +## + +​ + +Feature pass-through + +Claude Code treats an `ANTHROPIC_BASE_URL` gateway as an Anthropic-format endpoint and sends it the beta headers and request body fields it sends to `api.anthropic.com`, except a small set of diagnostics and defaults reserved for direct connections. Capabilities that add body fields pair them with a beta header, and the pair travels together. A gateway that strips the header while passing the body, or forwards an Anthropic-format body to an upstream with a different schema, produces hard `400` errors; only when both halves are absent together does the feature turn off quietly. A gateway that rewrites or redacts request bodies for content inspection breaks the pairing the same way stripping does, so inspect without modifying. The table notes where a feature deviates from the pairing. Fine-grained tool streaming is one of the direct-connection defaults: it is off by default whenever requests route through a custom base URL, and a gateway receives it when developers set [`CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING=1`](</docs/en/env-vars>). + +Feature| Header and body pair| Symptom when broken| Remediation +---|---|---|--- +[Adaptive reasoning](</docs/en/model-config#adjust-effort-level>)| No beta header. Claude Code sends `thinking: {"type": "adaptive"}` for Claude 4.6 and later, and treats model names it doesn’t recognize, such as gateway aliases, as current models that receive the field| `400` naming the `thinking` field or the `adaptive` tag when the upstream model build doesn’t accept it| Upgrade the upstream. On Opus 4.6 and Sonnet 4.6, developers can set `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` instead +[Context management](<https://platform.claude.com/docs/en/build-with-claude/context-management>)| Context management beta header pairs with the `context_management` body field| `400` with `Extra inputs are not permitted`. Common when a gateway accepts Anthropic-format requests but forwards them to Bedrock| Forward both, or [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/env-vars>) +[Extended context](<https://platform.claude.com/docs/en/build-with-claude/context-windows#1m-token-context-window>) and [interleaved thinking](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking>)| Beta headers only, no body field| Silently unavailable when the header is stripped; the upstream never sees the capability request| Forward `anthropic-beta` verbatim +Beta [tool fields](<https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview>)| Tool-related beta headers pair with tool schema fields such as `strict` and `defer_loading`| `400` naming the unrecognized tool schema field when the body passes through without its header| Forward both, or `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` +[Effort](<https://platform.claude.com/docs/en/build-with-claude/effort>) and [structured outputs](<https://platform.claude.com/docs/en/build-with-claude/structured-outputs>)| The `output_config` body field carries effort, structured-output format, and task budget settings; each pairs with its own beta header| `400` naming `output_config`, often `Extra inputs are not permitted`, on Bedrock and Vertex upstreams| Forward the field and its headers together +[Token counting](<https://platform.claude.com/docs/en/build-with-claude/token-counting>)| No beta pairing; uses the `count_tokens` endpoint| Claude Code falls back to estimating context usage locally| Expose the endpoint if you want exact counts + +The `ANTHROPIC_DEFAULT_*_MODEL_SUPPORTED_CAPABILITIES` [variables](</docs/en/model-config>) declare model capabilities only in the provider configurations: `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY`, and [`CLAUDE_CODE_USE_MANTLE`](</docs/en/amazon-bedrock#use-the-mantle-endpoint>). They have no effect behind an `ANTHROPIC_BASE_URL` gateway. + +### + +​ + +Automatic retry and error forwarding + +Claude Code retries automatically after some upstream rejections and disables the rejected capability for the rest of the conversation. Rejections of the `thinking` field, of [thinking signatures](<https://platform.claude.com/docs/en/build-with-claude/extended-thinking>), and of mid-conversation system messages all recover this way. Context management and tool schema field rejections do not retry; those `400` errors reach the developer. The retry logic matches on the upstream’s error wording, so forward error response bodies unmodified. A gateway that wraps upstream errors in its own envelope breaks the recovery path even when it preserves the status code. + +### + +​ + +Disable pre-release capabilities + +`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` stops Claude Code from sending pre-release capabilities and their body fields on every provider, including context management and the beta tool fields. It does not affect adaptive reasoning, which is selected by model rather than by beta, and it never suppresses the OAuth capability that subscription authentication requires. The set of capabilities Claude Code sends grows over releases. For current beta header strings, see the [beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>); test your gateway against new Claude Code releases rather than pinning to an observed list. + +## + +​ + +Model discovery + +When `ANTHROPIC_BASE_URL` points at a gateway that exposes the Anthropic Messages format, Claude Code can query the gateway’s `/v1/models` endpoint at startup and add the returned models to the `/model` picker. Developers enable it by setting [`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`](</docs/en/env-vars>), in their own environment or through managed settings. Discovery is off by default so that gateways backed by a shared API key do not surface every model the key can access to every user. This requires Claude Code v2.1.129 or later. + +### + +​ + +When discovery runs + +Discovery applies only to the Anthropic Messages format. It does not run when: + + * Any `CLAUDE_CODE_USE_*` provider variable is set, even if `ANTHROPIC_BASE_URL` is also set + * `ANTHROPIC_BASE_URL` is unset or points at `api.anthropic.com` + * Nonessential traffic is disabled, through [`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`](</docs/en/env-vars>) or organization policy + +### + +​ + +Request and response + +The request is `GET /v1/models?limit=1000` with a 3-second timeout, and any redirect is treated as failure so the credential cannot leak to a redirect target. A gateway that responds slowly or redirects `/v1/models`, even `http` to `https`, fails discovery silently; serve the endpoint directly at the configured base URL. The discovery request sends exactly one credential header: + + * `ANTHROPIC_AUTH_TOKEN` as a bearer token, when set + * Otherwise the resolved API key, including an [`apiKeyHelper`](</docs/en/llm-gateway-connect#rotate-credentials-with-apikeyhelper>) value, in the `x-api-key` header + +This differs from inference requests, which send a helper value in both headers. A gateway that authenticates `/v1/models` must accept `x-api-key` for helper deployments. Any headers from `ANTHROPIC_CUSTOM_HEADERS` are included as well. Claude Code reads `id` and the optional `display_name` from each entry in the response’s `data` array, and ignores entries whose `id` doesn’t begin with `claude` or `anthropic`: + + { + "data": [ + { "id": "claude-sonnet-4-6", "display_name": "Claude Sonnet 4.6" }, + { "id": "claude-opus-4-7" } + ] + } + +### + +​ + +Picker entries and caching + +The picker is the interactive model list that opens when a developer runs `/model` in Claude Code. Each discovered entry is labeled “From gateway” and uses `display_name` when provided. A discovered ID is skipped only when it exactly matches a row already in the picker, or when both the discovered and existing IDs resolve to [Fable](</docs/en/model-config#work-with-fable-5>). Built-in rows are keyed on aliases such as `sonnet`, so a discovered ID such as `claude-sonnet-4-6` adds its own “From gateway” row alongside the built-in entry. The [`availableModels` managed setting](</docs/en/settings#available-settings>) bounds what discovery can add. Results are cached to `~/.claude/cache/gateway-models.json`, or `%USERPROFILE%\.claude\cache\gateway-models.json` on Windows, and refreshed on each startup. If the request fails or the gateway does not implement `/v1/models`, the picker falls back to the cached list from the previous startup or to the built-in model list. If your gateway serves Claude models under aliases that don’t match the discovery filter, developers can add those aliases manually with the [model configuration](</docs/en/model-config>) variables. + +## + +​ + +Related resources + +For the rest of the gateway documentation set and the underlying API references: + + * [LLM gateways overview](</docs/en/llm-gateway>): what a gateway is and how it interacts with claude.ai subscriptions + * [Roll out an LLM gateway for your organization](</docs/en/llm-gateway-rollout>): the admin checklist that uses this contract + * [Connect Claude Code to an LLM gateway](</docs/en/llm-gateway-connect>): per-developer configuration and the troubleshooting table + * [Beta headers reference](<https://platform.claude.com/docs/en/api/beta-headers>): the current set of `anthropic-beta` values + * [Messages API](<https://platform.claude.com/docs/en/api/messages>): the API format an Anthropic-format gateway implements