Repository navigation
[v3.8.50] fix(auth): accept x-api-key without anthropic-version for claude-code user-agent (fixes #8655) - #8678
Conversation
… user-agent (fixes #8655) Claude Code sends requests with x-api-key and User-Agent headers, but omits anthropic-version. Previously, extractApiKey required anthropic-version to accept x-api-key fallback, rejecting valid Claude Code requests. By matching claude-code and anthropic SDK User-Agent strings, extractApiKey now accepts x-api-key for Claude Code clients.
⏸️ Ejetada do merge-train v3.8.49 — file-size frozen violationEsta PR foi ejetada do merge-train porque o diff faz Motivo da ejeção
Por que o frozen é restritivoA política do file-size ratchet no v3.8.49 congela o tamanho atual de arquivos server-side — não pode crescer até que v3.8.51 reaperte (issue #8768). Como o
Labels aplicadas
Próximos passos
|
Heads-up: this PR is running against a stale base
I verified this on a clean checkout of the current tip ( Currently failing here:
Please update the branch (the Update branch button, or rebase onto Note this is not a promise that every red disappears — a failure specific to the changes in this PR will survive the rebase, and No action was taken on this PR beyond this comment. |
|
Re-homed to |
Clean merge (no conflicts) — CHANGELOG.md diff vs release is empty (no base bullets lost). src/sse/services/auth.ts grew past the frozen file-size ceiling (2508 lines) once merged on top of the newer release tip (2503 lines); tighten the isClaudeClient gate back to a 2-variable/1-line-if shape (same behavior, same test coverage) so the file lands at 2506 lines, inside budget, instead of widening the ratchet baseline. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
|
Heads-up on the issue reference, not on the change itself: this PR body says it fixes #8655, but #8655 is the keyless OpenCode-Free ( The change itself looks fine and stands on its own; could you update the reference to the issue it actually addresses (or drop the For context: I re-triaged #8655 today and the reported root cause turned out to be different from what the reporter assumed — the quota endpoint is a red herring (it's dashboard-only and fails open); the real 403 comes from Cloudflare rejecting requests without CLI identity headers. That one needs a separate fix. |
f843bac
into
cheaper-inference:release/v3.8.50
…laude-code user-agent (fixes cheaper-inference#8655) (cheaper-inference#8678) Validated in local merge-train T6 (ungrouped batch 1)
Summary
Fixes #8655.
Root Cause
Claude Code and official Anthropic SDKs send HTTP requests containing
x-api-keyand standardUser-Agentheaders (e.g.claude-code/0.2.29 node/v20.18.0 darwin-x64oranthropic-typescript/0.25.0), but omit the optionalanthropic-versionheader.Previously,
extractApiKeychecked if the request was an Anthropic client by verifyingisClaudeClient = hasAnthropicVersionHeader || /claude-code|claude-cli|@anthropic-ai/i.test(userAgent). Requests withx-api-keywere only honored ifisClaudeClientevaluated to true. Because the regex did not match standard Anthropic SDK user agents (such asanthropic-typescriptoranthropic-python) and requiredanthropic-versionif the user agent didn't match@anthropic-ai, requests missinganthropic-versionwere rejected.Fix
Updated
isClaudeClientinsrc/sse/services/auth.tsto match/claude-code|claude-cli|anthropic/iagainstUser-Agent. Any request carryingx-api-keywith a Claude Code or Anthropic user agent (oranthropic-versionheader) is now properly recognized and authenticated.Verification
tests/unit/auth-extract-api-key.test.tscovering Claude Code and Anthropic SDK user agents withoutanthropic-version.node --import tsx/esm --test tests/unit/auth-extract-api-key.test.ts(28/28 tests passing).npx tsc --pretty false -p tsconfig.typecheck-core.json.