Repository navigation
fix(responses): stop internal metadata reaching strict upstreams - #36412
Souravrajvi0 wants to merge 4 commits into
Conversation
When proxy-internal fields leaked into the provider-facing metadata
parameter (including empty {}), strict OpenAI-compatible /v1/responses
backends returned HTTP 400. Only forward caller metadata: prefer
litellm_metadata.requester_metadata on proxy routes and drop metadata
entirely when no caller-supplied values exist.
Fixes BerriAI#35780
Greptile SummaryThis PR changes Responses API optional-parameter assembly to separate caller metadata from LiteLLM proxy metadata and omit empty or internal metadata before provider dispatch.
Confidence Score: 4/5The PR should not merge until caller metadata containing a The changed helper selection can silently truncate otherwise valid caller metadata, while the additional mutation concern is non-blocking. Files Needing Attention: litellm/responses/utils.py
|
| Filename | Overview |
|---|---|
| litellm/responses/utils.py | Reworks metadata source selection and filtering, but double-interprets a caller-owned requester_metadata key and violates the repository's immutability convention. |
| tests/test_litellm/responses/test_responses_utils.py | Adds focused regression tests for the intended metadata-routing cases without weakening existing assertions. |
Reviews (1): Last reviewed commit: "fix(responses): stop internal metadata r..." | Re-trigger Greptile
|
|
||
| if metadata_source is not None: | ||
| from litellm.utils import get_requester_metadata | ||
|
|
There was a problem hiding this comment.
Caller metadata is double-unwrapped
When caller metadata contains a dictionary-valued requester_metadata key alongside other valid fields, get_requester_metadata() treats that key as another internal envelope and returns it early, silently dropping the caller's sibling metadata fields from the upstream request.
| from litellm.utils import add_openai_metadata | ||
| litellm_metadata = params.get("litellm_metadata") | ||
| if not isinstance(litellm_metadata, dict): | ||
| litellm_metadata = {} |
There was a problem hiding this comment.
Metadata assembly mutates local state
The new source-selection logic repeatedly reassigns local variables and mutates non_default_params through assignment and pop(), contrary to the repository's immutable-construction convention and making the final metadata provenance harder to reason about.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Use add_openai_metadata on the resolved metadata source instead of get_requester_metadata, which treated caller-owned requester_metadata keys as another proxy envelope and dropped sibling fields. Build the final optional-params dict without mutating metadata via pop.
Use Final assignments and a single metadata_source expression so LIT001 and LIT010 budgets are not exceeded.
Summary
Fixes #35780
Strict OpenAI-compatible
/v1/responsesupstreams were rejecting proxy requests withHTTP 400: Unsupported parameter: metadataeven when the client did not pass ametadataargument.Root cause: internal/proxy metadata (including empty
{}) was being serialized into the provider-facingmetadatarequest field during optional-param assembly.Changes
ResponsesAPIRequestUtils.get_requested_response_api_optional_param()to:litellm_metadata.requester_metadata(proxy snapshot of caller metadata)metadataon proxy routes (detected viauser_api_key_*keys inlitellm_metadata){}upstreamrequester_metadataroutingTest plan
pytest tests/test_litellm/responses/test_responses_utils.py(32 passed)pytest tests/llm_responses_api_testing/test_openai_responses_api.py::test_openai_responses_litellm_router_no_metadatapytest tests/llm_responses_api_testing/test_openai_responses_api.py::test_openai_responses_litellm_router_with_metadata