mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-22 13:33:29 +08:00
bdc4c1e8b8
Anthropic SDK assigns distinct semantics to the two env vars: - ANTHROPIC_API_KEY -> x-api-key - ANTHROPIC_AUTH_TOKEN -> Authorization: Bearer The Claude adapter previously collapsed both into AuthStrategy::Anthropic and then emitted Authorization: Bearer regardless, breaking strict Anthropic-protocol endpoints (Anthropic official, Cloudflare AI Gateway, OpenCode Go, DashScope) and silently overriding the user's intended auth scheme. - claude::extract_auth: infer strategy from env var name (ANTHROPIC_AUTH_TOKEN -> ClaudeAuth, ANTHROPIC_API_KEY -> Anthropic), matching the precedence already used by extract_key. - claude::get_auth_headers: split the Anthropic arm so it emits x-api-key, while ClaudeAuth and Bearer continue to use Bearer. - stream_check: reuse ClaudeAdapter::get_auth_headers as the single source of truth, replacing the prior "always Bearer + maybe x-api-key" double injection that produced auth conflicts and false-negative health checks. - Cover each strategy -> header mapping and env-var precedence with new unit tests in claude.rs. Refs #2368, #2380