From 8d803ec66763117c1f7840dada8d3bd0541a0340 Mon Sep 17 00:00:00 2001 From: Darien Kindlund Date: Fri, 17 Apr 2026 10:52:22 -0400 Subject: [PATCH] fix(proxy): clear litellm_call_id_from_client flag when no header supplied Defensive guard: when the x-litellm-call-id header is absent, explicitly set litellm_call_id_from_client=False on the request data dict. Without this reset, a body-injected `"litellm_call_id_from_client": true` field would survive into kwargs and flip the precedence in get_spend_logs_id, causing the auto-generated UUID to be recorded as request_id instead of the provider response.id and breaking lookups by response ID. Applied to all three handler locations: - common_request_processing.py (OpenAI-compatible /chat/completions, etc.) - google_endpoints/endpoints.py:generateContent - google_endpoints/endpoints.py:streamGenerateContent Addresses Greptile P2 review feedback on PR #25952. Co-Authored-By: Claude Opus 4.7 (1M context) --- litellm/proxy/common_request_processing.py | 4 ++++ litellm/proxy/google_endpoints/endpoints.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py index 96fb34c11b8..4a3e92798da 100644 --- a/litellm/proxy/common_request_processing.py +++ b/litellm/proxy/common_request_processing.py @@ -789,6 +789,10 @@ class ProxyBaseLLMRequestProcessing: self.data["litellm_call_id_from_client"] = True else: self.data["litellm_call_id"] = str(uuid.uuid4()) + # Defensive: explicitly clear the flag so a body-injected + # `litellm_call_id_from_client: true` cannot flip precedence + # in get_spend_logs_id when no header was actually supplied. + self.data["litellm_call_id_from_client"] = False DDSpanTagger.tag_call_id(self.data.get("litellm_call_id")) DDSpanTagger.tag_request( user_api_key_dict=user_api_key_dict, diff --git a/litellm/proxy/google_endpoints/endpoints.py b/litellm/proxy/google_endpoints/endpoints.py index bf74fcacbf7..aa287ce3f16 100644 --- a/litellm/proxy/google_endpoints/endpoints.py +++ b/litellm/proxy/google_endpoints/endpoints.py @@ -64,6 +64,10 @@ async def google_generate_content( data["litellm_call_id_from_client"] = True else: data["litellm_call_id"] = str(uuid.uuid4()) + # Defensive: explicitly clear the flag so a body-injected + # `litellm_call_id_from_client: true` cannot flip precedence + # in get_spend_logs_id when no header was actually supplied. + data["litellm_call_id_from_client"] = False logging_obj, data = litellm.utils.function_setup( original_function="agenerate_content", rules_obj=litellm.utils.Rules(), @@ -130,6 +134,10 @@ async def google_stream_generate_content( data["litellm_call_id_from_client"] = True else: data["litellm_call_id"] = str(uuid.uuid4()) + # Defensive: explicitly clear the flag so a body-injected + # `litellm_call_id_from_client: true` cannot flip precedence + # in get_spend_logs_id when no header was actually supplied. + data["litellm_call_id_from_client"] = False logging_obj, data = litellm.utils.function_setup( original_function="agenerate_content_stream", rules_obj=litellm.utils.Rules(),