From 079d397c6d04cce33ef1f849cd40045cb8599001 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 6 Jun 2025 14:40:28 -0700 Subject: [PATCH] fix(vertex_and_google_ai_studio.py): preserve vertex response id --- .../vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py | 7 +++++-- litellm/types/llms/vertex_ai.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index 1af54f9291f..495597a3812 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -1230,7 +1230,9 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): ) model_response.choices = [] - model_response.id = completion_response.get("responseId", None) + response_id = completion_response.get("responseId") + if response_id: + model_response.id = response_id url_context_metadata: List[dict] = [] try: grounding_metadata: List[dict] = [] @@ -1848,7 +1850,8 @@ class ModelResponseIterator: from litellm.types.utils import ModelResponseStream processed_chunk = GenerateContentResponseBody(**chunk) # type: ignore - model_response = ModelResponseStream(choices=[]) + response_id = processed_chunk.get("responseId") + model_response = ModelResponseStream(choices=[], id=response_id) usage: Optional[Usage] = None _candidates: Optional[List[Candidates]] = processed_chunk.get("candidates") grounding_metadata: List[dict] = [] diff --git a/litellm/types/llms/vertex_ai.py b/litellm/types/llms/vertex_ai.py index 7407d0c896c..ded64cee6c3 100644 --- a/litellm/types/llms/vertex_ai.py +++ b/litellm/types/llms/vertex_ai.py @@ -377,6 +377,7 @@ class GenerateContentResponseBody(TypedDict, total=False): candidates: List[Candidates] promptFeedback: PromptFeedback usageMetadata: Required[UsageMetadata] + responseId: str class FineTuneHyperparameters(TypedDict, total=False):