Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(vertex_and_google_ai_studio.py): preserve vertex response id

Krrish Dholakia079d397c6d04
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):