Skip to content

fix(anthropic_messages): strip non-user_id keys from metadata before forwarding - #27262

Closed
mateo-berri wants to merge 2 commits into
litellm_internal_stagingfrom
litellm_fix-anthropic-vertex-metadata-strip
Closed

fix(anthropic_messages): strip non-user_id keys from metadata before forwarding#27262
mateo-berri wants to merge 2 commits into
litellm_internal_stagingfrom
litellm_fix-anthropic-vertex-metadata-strip

Conversation

@mateo-berri

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

Changes

The Anthropic Messages API only accepts user_id inside metadata, and Vertex AI / Azure AI Anthropic mirror that contract — they 400 with metadata.tags: Extra inputs are not permitted on any other key.

PR #24661 added this filter to the chat/completions path (AnthropicConfig.transform_request), but the unified /v1/messages endpoint (used by Claude Code via ANTHROPIC_BASE_URL) goes through AnthropicMessagesConfig.transform_anthropic_messages_request, which had no equivalent guard. Routing/budget tags injected by key/team/project metadata or deployment-level routing therefore leaked into the outgoing metadata dict and broke requests against Vertex AI Anthropic.

This PR applies the same final-strip filter in the unified messages transform so the safeguard covers both code paths, and adds a unit test in tests/test_litellm/ covering the filter behavior.

Files touched

  • litellm/llms/anthropic/experimental_pass_through/messages/transformation.py — strip non-user_id keys from metadata before forwarding.
  • tests/test_litellm/.../test_anthropic_messages_metadata_filter.py — new unit test for the filter.

Note: this branch also carries a previously-merged UI fix commit (f969eb8c48 — include unified access groups in Add Model dropdown, LIT-2783) which is part of the source branch; the primary change of this PR is the anthropic messages metadata fix above.

Slack Thread

Open in Web Open in Cursor 

cursoragent and others added 2 commits May 4, 2026 19:17
The 'Model Access Group' picker in the Add Model flow only listed legacy
access groups discovered from existing deployments' `model_info.access_groups`
(via /models?only_model_access_groups=true). Unified access groups created
through the Access Groups page (stored in LiteLLM_AccessGroupTable, served
by /v1/access_group) were never merged in, so a freshly-created group like
'Engineering' did not appear and admins had to free-type it from memory.

Pull both sources:
- AddModelForm: combine the legacy /models response with useAccessGroups()
- add_auto_router_tab and edit_auto_router_modal: same merge for parity
- ModelsAndEndpointsView.availableModelAccessGroups (powers ModelInfoView's
  edit dropdown) now also folds in unified group names

Names are deduped via a Set and sorted for stable rendering. The hook is
gated on admin role inside useAccessGroups itself, so non-admins see the
same list they did before.

Adds an AddModelForm test that opens the dropdown and asserts both the
legacy entries and a mocked unified group are listed.

Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
…forwarding

The Anthropic Messages API only accepts `user_id` inside `metadata`, and
Vertex AI / Azure AI Anthropic mirror that contract — they 400 with
`metadata.tags: Extra inputs are not permitted` on any other key.

PR #24661 added this filter to the chat/completions path
(`AnthropicConfig.transform_request`), but the unified `/v1/messages`
endpoint (used by Claude Code via `ANTHROPIC_BASE_URL`) goes through
`AnthropicMessagesConfig.transform_anthropic_messages_request`, which had
no equivalent guard. Routing/budget tags injected by key/team/project
metadata or deployment-level routing therefore leaked into the outgoing
`metadata` dict and broke requests against Vertex AI Anthropic.

Apply the same final-strip filter in the unified messages transform so
the safeguard covers both code paths.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ claude
❌ cursoragent
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Aug 5, 2026
@github-actions github-actions Bot closed this Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants