Skip to content

Filter unsupported anthropic betas/fields on proxy forward#362

Open
braisedpork1964 wants to merge 1 commit into
InternLM:v1.0.0from
braisedpork1964:fix-anthropic-request
Open

Filter unsupported anthropic betas/fields on proxy forward#362
braisedpork1964 wants to merge 1 commit into
InternLM:v1.0.0from
braisedpork1964:fix-anthropic-request

Conversation

@braisedpork1964

Copy link
Copy Markdown
Collaborator

Drop SDK-injected anthropic_beta flags (keep allowlist) and context_management before forwarding /messages upstream, on both body and header. Configurable via PROXY_ANTHROPIC_BETA_ALLOWLIST / PROXY_ANTHROPIC_DROP_FIELDS. No impact on lmdeploy/sglang.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@braisedpork1964

Copy link
Copy Markdown
Collaborator Author

Only drops fields; core messages/tools/system untouched.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the Anthropic /messages proxy-forwarding path by filtering out SDK/CLI-injected beta flags and top-level body fields that some upstream backends (notably Bedrock) reject, while allowing an explicit allowlist to pass through.

Changes:

  • Add env-configurable allowlist filtering for anthropic_beta (body) and anthropic-beta (header) before forwarding upstream.
  • Drop selected top-level Anthropic request body fields (default: context_management) on /messages requests.
  • Introduce env vars PROXY_ANTHROPIC_BETA_ALLOWLIST and PROXY_ANTHROPIC_DROP_FIELDS to control behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lagent/adapters/proxy.py
# keep only the allowlist (see _FORWARD_ANTHROPIC_BETAS).
betas = request_data.get('anthropic_beta')
if isinstance(betas, list):
kept = [b for b in betas if b in _FORWARD_ANTHROPIC_BETAS]
Comment thread lagent/adapters/proxy.py
Comment on lines +382 to +387
# Drop SDK-injected beta flags the upstream (e.g. Bedrock) rejects;
# keep only the allowlist (see _FORWARD_ANTHROPIC_BETAS).
betas = request_data.get('anthropic_beta')
if isinstance(betas, list):
kept = [b for b in betas if b in _FORWARD_ANTHROPIC_BETAS]
if kept:
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.

2 participants