Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions litellm/llms/vertex_ai/gemini/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions tests/test_litellm/llms/vertex_ai/test_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading