Add ANTHROPIC_CUSTOM_HEADERS for gateway auth - #6
Open
pre wants to merge 1 commit into
Open
Conversation
Gateways fronted by Azure API Management authenticate on a header meat never sent, so pointing ANTHROPIC_BASE_URL at one returned a 401 with no way to supply the missing credential. Parse $ANTHROPIC_CUSTOM_HEADERS in the same "Name: value" per line format Claude Code uses, and apply the headers after the defaults so a gateway can override one. A malformed line, an invalid field-name, or a control character in a value is a hard error, since a silently dropped auth header resurfaces as an opaque 401. The value is a credential, so it is never echoed in an error. Their presence also counts as configuration: a gateway-authenticated user may have no ANTHROPIC_API_KEY at all, so an empty key no longer falls through to exe.dev discovery or fails the Generate guard.
pre
force-pushed
the
feat/custom-headers
branch
from
August 4, 2026 09:48
07058b3 to
1e9ff22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pointing
ANTHROPIC_BASE_URLat a corporate LLM gateway fronted by Azure API Management fails with a 401: the gateway authenticates onOcp-Apim-Subscription-Key, a header meat has no way to send.This adds
$ANTHROPIC_CUSTOM_HEADERS, parsed in the sameName: valueper-line format Claude Code already uses, so the same env var configures both tools.Behavior
anthropic-versionwhen it needs to.ANTHROPIC_API_KEYat all, so an empty key no longer falls through to exe.dev discovery, and no longer trips theGenerateguard. An emptyx-api-keyis not sent.Behavior is unchanged when the variable is unset.
Testing
12 new cases: table-driven parsing and rejection tests, an error-does-not-leak-the-value test, and
httptestassertions that the header reaches the wire, that it overrides a default, that header-only auth works, and that no credential at all still errors.go build ./...,go vet ./..., andgo test -race ./...pass;gofmtclean. Also verified end to end against a real APIM-fronted gateway, where it produced an abridged diff instead of the 401.