fix: prevent key-level metadata.tags from leaking into Bedrock passthrough body - #30666
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes a bug where key-level
Confidence Score: 5/5Safe to merge; the one-line change to LITELLM_METADATA_ROUTES and the auth_checks pre-seed are narrow and well-tested for the key-level tag path. Both code changes are small, targeted, and consistent with existing patterns in the codebase. The new unit tests directly cover the routing function change, and the guardrails header fallback logic already reads from both litellm/proxy/auth/auth_checks.py — the pre-seeding runs after apply_client_tag_policy_pre_auth, leaving x-litellm-tags header tags still routed to
|
| Filename | Overview |
|---|---|
| litellm/proxy/litellm_pre_call_utils.py | Adds "bedrock" to LITELLM_METADATA_ROUTES so _get_metadata_variable_name returns "litellm_metadata" for all Bedrock passthrough paths; one-line, consistent with existing entries. |
| litellm/proxy/auth/auth_checks.py | Pre-seeds litellm_metadata in common_checks for bedrock routes so apply_key_tags_pre_auth routes key-level tags correctly; header-sourced x-litellm-tags still go to metadata (apply_client_tag_policy_pre_auth runs before this pre-seed). |
| tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py | Updates existing bedrock-path test to expect headers in litellm_metadata, correctly reflecting new routing behaviour; test assertions remain equivalent in strength. |
| tests/test_litellm/proxy/test_litellm_pre_call_utils.py | Adds two new unit tests confirming _get_metadata_variable_name returns "litellm_metadata" for bedrock invoke and converse URLs; directly covers the litellm_pre_call_utils.py fix. |
Reviews (4): Last reviewed commit: "fix: prevent key-level metadata.tags fro..." | Re-trigger Greptile
|
Thanks for the PR! A couple of things to get this over the finish line:
Once those are addressed we'll take another look — appreciate the contribution! |
|
@Sameerlite Hi there, thanks for your review! The only CI failure is the same pre-existing infrastructure issue as other litellm PRs — lint fails because type_discipline_gate.py is missing from the CI environment. Not related to this change. I've also added regression tests for bedrock routes and updated the existing passthrough test. Greptile score should improve on the next run. |
|
@factnn Can you rebase with latest litellm_internal_staging? |
b0d28d1 to
034bf8f
Compare
|
@Sameerlite Done, my pleasure. |
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
|
Thanks for the rebase and for the updated tests! A couple of things still needed before we can merge:
Triggering a fresh Greptile review on the updated commit: Once those are addressed, we'll take another look! |
d7a348d to
e496883
Compare
@Sameerlite two updates: 1.All three tests pass in CI: https://github.com/BerriAI/litellm/actions/runs/27896275028/job/82548278630. The 3 CI tests are as below and screenshots are attached. 2.Adopted the Veria AI suggestion — added a litellm_metadata pre-seed in auth_checks.py before apply_key_tags_pre_auth. That one extra line is what drags down codecov/patch, since the auth-stage path isn't covered by unit tests.
|
|
The PR looks good. The changes are correct and the two-part approach is sound:
The CI passing on all three targeted tests ( This is ready to merge from a technical standpoint. |
|
This has been merged (via a mirror branch to run CircleCI). Thank you so much for the contribution! |


Fixes #30629
Key-level spend-tracking tags were injected into
data["metadata"]for Bedrock passthrough routes, then forwarded in the provider request
body. Bedrock rejects non-
user_idmetadata fields with HTTP 400.Add
"bedrock"toLITELLM_METADATA_ROUTESso tags are stored indata["litellm_metadata"]instead. Spend tracking reads from bothlocations, so tags are preserved for billing without leaking to the
upstream provider.
Consistent with the existing handling for
/v1/messagesandresponsesroutes.Type
Bug Fix
Changes
litellm/proxy/litellm_pre_call_utils.py: 1 line