Skip to content

fix(claude-code): add missing anthropic-beta oauth header - #58

Open
doanhv wants to merge 1 commit into
snipeship:mainfrom
doanhv:fix/oauth-beta-header-missing-claude-code-route
Open

fix(claude-code): add missing anthropic-beta oauth header#58
doanhv wants to merge 1 commit into
snipeship:mainfrom
doanhv:fix/oauth-beta-header-missing-claude-code-route

Conversation

@doanhv

@doanhv doanhv commented Jul 2, 2026

Copy link
Copy Markdown

Fixes #57

Problem

ClaudeCodeProvider.prepareHeaders() sets Authorization: Bearer <token> for OAuth accounts but never sets anthropic-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 misleading 401 x-api-key header is required — even with a valid, unexpired, correctly-entitled OAuth token.

Confirmed the token itself is fine: calling api.anthropic.com directly 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 its ANTHROPIC_BETA constant in compat/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-20 when attaching the OAuth Bearer token in ClaudeCodeProvider.prepareHeaders(), merging with any beta value already present on the incoming request rather than clobbering it.

Test plan

  • claude-haiku-4-5 via /v1/claude-code/v1/messages still returns 200 (no regression)
  • claude-sonnet-5 via 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)
  • Direct comparison against calling api.anthropic.com with the same token confirms matching behavior post-fix

See #57 for full repro details and the confusing secondary 401-via-502-retry symptom this can produce when only one account is configured.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-code provider: missing anthropic-beta oauth header causes 401 for non-Haiku models

1 participant