fix: merge client anthropic-beta tags to unblock 1M context (#54)#56
fix: merge client anthropic-beta tags to unblock 1M context (#54)#56
Conversation
The hardcoded anthropic-beta header in ClaudeAPIAdapter prevented Max Plan subscribers from enabling the 1M context window (context-1m-2025-08-07) because client-supplied beta tags were dropped and anthropic-beta was in blocked_overrides for CLI header merging. Required OAuth tags (claude-code-20250219, oauth-2025-04-20) are now always preserved, while client-provided and CLI-detected beta tags are merged in so any Claude CLI beta (context-1m, interleaved-thinking, etc.) flows through to the upstream API.
There was a problem hiding this comment.
Pull request overview
Unblocks forwarding Anthropic 1M-context (and other) beta tags by changing the Claude API adapter to merge anthropic-beta values from the client and Claude CLI detection cache while still enforcing required OAuth/Claude Code tags.
Changes:
- Add
_merge_anthropic_betahelper to union/dedupe required + client + CLI-detected beta tags. - Stop treating
anthropic-betaas a blocked CLI override; merge it instead of overwriting. - Extend unit tests to cover required-tag enforcement and client/CLI beta-tag merging behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
ccproxy/plugins/claude_api/adapter.py |
Implements beta-tag merging logic and adjusts CLI header handling to preserve client-supplied tags. |
tests/plugins/claude_api/unit/test_adapter.py |
Adds/extends tests validating required tags and merge behavior for client + CLI-detected betas. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| filtered_headers["anthropic-version"] = "2023-06-01" | ||
| filtered_headers["anthropic-beta"] = "claude-code-20250219,oauth-2025-04-20" | ||
| filtered_headers["anthropic-beta"] = self._merge_anthropic_beta( | ||
| headers.get("anthropic-beta") or headers.get("Anthropic-Beta") |
There was a problem hiding this comment.
prepare_provider_request is documented/used with lowercase header keys (see BaseHTTPAdapter contract and extract_request_headers), so checking headers.get("Anthropic-Beta") is redundant and slightly confusing. Consider relying on headers.get("anthropic-beta") (or normalizing keys once if you want true case-insensitive lookup).
| headers.get("anthropic-beta") or headers.get("Anthropic-Beta") | |
| headers.get("anthropic-beta") |
Summary
anthropic-betaheader inClaudeAPIAdapterwas hardcoded toclaude-code-20250219,oauth-2025-04-20and listed inblocked_overrides, so client-supplied beta tags (notablycontext-1m-2025-08-07for Max Plan 1M context) were silently dropped._merge_anthropic_betahelper. The detection-service cache already captures the full set Claude CLI ships (interleaved-thinking, context-management, prompt-caching-scope, etc.), so those flow through as well.anthropic-betaremoved fromblocked_overrides; CLI header loop merges instead of overwriting.Test plan
uv run pytest tests/plugins/claude_api/unit/test_adapter.py(18 passed, including 3 new cases covering client merge, CLI-detected merge, and the helper)make pre-commit