From 1be6590e1c783e23f8ab99cd7886e09a23a7ec06 Mon Sep 17 00:00:00 2001
From: Bhanu Teja
Date: Sun, 7 Sep 2025 18:09:36 +0530
Subject: [PATCH 1/3] Update transformation.py
extra body params passed to the request body
---
litellm/llms/vertex_ai/gemini/transformation.py | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py
index 267ca61ef5d7..a8cd3072e2a8 100644
--- a/litellm/llms/vertex_ai/gemini/transformation.py
+++ b/litellm/llms/vertex_ai/gemini/transformation.py
@@ -468,6 +468,12 @@ def _transform_request_body(
data["generationConfig"] = generation_config
if cached_content is not None:
data["cachedContent"] = cached_content
+
+ # Add any extra body params passed to the request body
+ extra_body = optional_params.get("extra_body", {})
+ if extra_body is not None:
+ data = {**extra_body, **data}
+
except Exception as e:
raise e
From ebebde2bddc36a096fd6b91540dab15c9aadb266 Mon Sep 17 00:00:00 2001
From: Bhanu Teja
Date: Sun, 7 Sep 2025 18:11:37 +0530
Subject: [PATCH 2/3] Update test_vertex.py
---
.../llms/vertex_ai/test_vertex.py | 29 +++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex.py b/tests/test_litellm/llms/vertex_ai/test_vertex.py
index 7e683d1f54eb..91e4f490c8bc 100644
--- a/tests/test_litellm/llms/vertex_ai/test_vertex.py
+++ b/tests/test_litellm/llms/vertex_ai/test_vertex.py
@@ -1503,3 +1503,32 @@ def test_system_prompt_only_adds_blank_user_message():
#########################################################
assert len(data["system_instruction"]) == 1
assert data["system_instruction"]["parts"][0]["text"] == SYSTEM_INSTRUCTION
+
+def test_extra_body_labels_added_and_existing_fields_not_overridden():
+ """
+ Test that list of parameters sent as "extra_body" are added to the request body and existing fields are not overridden.
+
+ Relevant Issue - https://github.com/BerriAI/litellm/issues/13692
+ """
+ data = _transform_request_body(
+ messages=[{"role": "system", "content": "System instructions for the model"}],
+ model="gemini-2.5-flash",
+ optional_params={
+ "extra_body": {
+ "labels": {"team": "ml"},
+ "cachedContent": "should_not_override"
+ }
+ },
+ custom_llm_provider="vertex_ai",
+ litellm_params={},
+ cached_content="pre_set",
+ )
+
+ print("Final data with extra_body: ", data)
+
+ # validate that extra_body fields are added
+ assert "labels" in data
+ assert data["labels"] == {"team": "ml"}
+
+ # validate that existing fields are not overridden
+ assert data["cachedContent"] == "pre_set"
From 35d18a67f2ecbacecac58a343c867e6cc6c8db31 Mon Sep 17 00:00:00 2001
From: Bhanu Teja
Date: Sun, 7 Sep 2025 18:46:55 +0530
Subject: [PATCH 3/3] Update poetry.lock
---
poetry.lock | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/poetry.lock b/poetry.lock
index 771bb6d486e4..41182d12bff4 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -9182,4 +9182,4 @@ utils = ["numpydoc"]
[metadata]
lock-version = "2.1"
python-versions = ">=3.8.1,<4.0, !=3.9.7"
-content-hash = "8ebdb444c0ff253857f90d3ec9926a58d23d4482c644fd158a047f0c0f892bb9"
+content-hash = "54374b906931afe92861b6b9b226751579c0d342f650bc8f7ebaf4c5882d6249"