Skip to content

fix: merge client anthropic-beta tags to unblock 1M context (#54)#56

Merged
CaddyGlow merged 1 commit intomainfrom
fix/issue-54-anthropic-beta-merge
Apr 13, 2026
Merged

fix: merge client anthropic-beta tags to unblock 1M context (#54)#56
CaddyGlow merged 1 commit intomainfrom
fix/issue-54-anthropic-beta-merge

Conversation

@CaddyGlow
Copy link
Copy Markdown
Owner

Summary

  • Fixes anthropic-beta header is hardcoded, preventing 1M context window #54. The anthropic-beta header in ClaudeAPIAdapter was hardcoded to claude-code-20250219,oauth-2025-04-20 and listed in blocked_overrides, so client-supplied beta tags (notably context-1m-2025-08-07 for Max Plan 1M context) were silently dropped.
  • Required OAuth tags are still always injected, but client-provided and CLI-detected beta tags are now merged in via a new _merge_anthropic_beta helper. 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-beta removed from blocked_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

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.
Copilot AI review requested due to automatic review settings April 13, 2026 09:33
@CaddyGlow CaddyGlow merged commit 97945a5 into main Apr 13, 2026
9 checks passed
@CaddyGlow CaddyGlow deleted the fix/issue-54-anthropic-beta-merge branch April 13, 2026 09:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_beta helper to union/dedupe required + client + CLI-detected beta tags.
  • Stop treating anthropic-beta as 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")
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
headers.get("anthropic-beta") or headers.get("Anthropic-Beta")
headers.get("anthropic-beta")

Copilot uses AI. Check for mistakes.
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.

anthropic-beta header is hardcoded, preventing 1M context window

2 participants