fix(claude-code): add missing anthropic-beta oauth header - #58
Open
doanhv wants to merge 1 commit into
Open
Conversation
ClaudeCodeProvider.prepareHeaders() sets Authorization: Bearer <token> for OAuth accounts but never sets anthropic-beta: oauth-2025-04-20. Anthropic accepts requests without it for some models (observed: claude-haiku-4-5) but rejects others (observed: claude-sonnet-5, claude-sonnet-4-5) with a misleading 401 "x-api-key header is required" — even though the account has a valid, unexpired OAuth token with the right entitlement (confirmed by calling the API directly with the same token, bypassing ccflare, which correctly returns a 429 for the same model instead of a 401). Merges into any anthropic-beta value already present on the request rather than overwriting it.
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.
Fixes #57
Problem
ClaudeCodeProvider.prepareHeaders()setsAuthorization: Bearer <token>for OAuth accounts but never setsanthropic-beta: oauth-2025-04-20. Anthropic silently accepts some models without it (observed:claude-haiku-4-5) but rejects others (observed:claude-sonnet-5,claude-sonnet-4-5) with a misleading401 x-api-key header is required— even with a valid, unexpired, correctly-entitled OAuth token.Confirmed the token itself is fine: calling
api.anthropic.comdirectly with the same token + the beta header (bypassing ccflare) authenticates correctly for all of the above models.The compat route (
/v1/ccflare/*) already sets this header via itsANTHROPIC_BETAconstant incompat/handler.ts; the native provider route (/v1/claude-code/*) — the one the README documents for pointing Anthropic SDKs directly at ccflare — did not.Fix
Add
anthropic-beta: oauth-2025-04-20when attaching the OAuth Bearer token inClaudeCodeProvider.prepareHeaders(), merging with any beta value already present on the incoming request rather than clobbering it.Test plan
claude-haiku-4-5via/v1/claude-code/v1/messagesstill returns 200 (no regression)claude-sonnet-5via the same route no longer 401s on the auth layer — first internal attempt is now correctly authenticated (verified with temporary debug logging showing the account is selected and a real request reaches Anthropic)api.anthropic.comwith the same token confirms matching behavior post-fixSee #57 for full repro details and the confusing secondary 401-via-502-retry symptom this can produce when only one account is configured.