feat: support ANTHROPIC_AUTH_TOKEN for bearer-auth Anthropic gateways#448
Open
Steven Robbins (grumpydev) wants to merge 1 commit into
Open
feat: support ANTHROPIC_AUTH_TOKEN for bearer-auth Anthropic gateways#448Steven Robbins (grumpydev) wants to merge 1 commit into
Steven Robbins (grumpydev) wants to merge 1 commit into
Conversation
Some Anthropic-compatible gateways authenticate with an `Authorization: Bearer <token>` header rather than Anthropic's `x-api-key`. OpenWiki could only send `x-api-key`, so those gateways returned 401 even with a valid token, and there was no way to configure a bearer token. - Add ANTHROPIC_AUTH_TOKEN as a managed env var (persisted, shown masked in the credential diagnostics panel like other secrets). - When ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN are both set, ANTHROPIC_API_KEY is no longer required (no more setup prompt every run), and the provider auto-resolves to anthropic. - Build the Anthropic client with the token as a bearer credential; with no API key set, use a createClient hook so only the bearer header is sent (no bogus x-api-key). Setting both still sends both headers. - Document the bearer-token gateway setup under "Alternative base URLs". Tests: constants.test.ts (api-key waiver, provider detection, resolveProviderAuthToken) and create-model.test.ts (bearer-only, both-headers, and api-key-only header wiring). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Steven Robbins (grumpydev)
marked this pull request as ready for review
July 23, 2026 13:27
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.
What & why
Some Anthropic-compatible gateways authenticate with an
Authorization: Bearer <token>header rather than Anthropic'sx-api-key. OpenWiki could only sendx-api-key, so those gateways returned401 unauthorizedeven with a valid token — and there was no first-class way to configure a bearer token (ChatAnthropicalso refuses to construct without an API key, so the CLI prompted for credentials on every launch).This adds native support for
ANTHROPIC_AUTH_TOKEN.Changes
ANTHROPIC_AUTH_TOKENis now a managed env var — persisted to~/.openwiki/.envand shown (masked, like other secrets) in the credential diagnostics panel.ANTHROPIC_BASE_URLandANTHROPIC_AUTH_TOKENare both set,ANTHROPIC_API_KEYis not required (getMissingProviderEnvKeywaives it), so there's no setup prompt every run.resolveConfiguredProvideralso auto-selectsanthropicfrom that pair.clientOptions.authToken. With no API key set, acreateClienthook builds the client so only the bearer header is sent (no bogusx-api-key). Setting bothANTHROPIC_API_KEYandANTHROPIC_AUTH_TOKENsends both headers.@anthropic-ai/sdk@^0.103.0as a direct dependency (matches@langchain/anthropic's own range; needed for thecreateClienthook). pnpm dedupes to a single 0.103.0.How tested
test/constants.test.ts: API-key waiver when base URL + auth token present (and still-required when only one is present), provider auto-detection, andresolveProviderAuthTokentrimming/blank handling.test/create-model.test.ts: bearer-only wiring (client built withauthTokenand a nullapiKey, so nox-api-key), both-headers case, and the unchanged api-key-only case.pnpm run typecheck,prettier --check, andeslintpass on the changed files; the changed-area test suites are green (124/124). Note: the model-construction tests assert the resolved client config without firing a network request, matching the existingcreate-model.test.tspattern.