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(gemini): forward seed to the Gemini API instead of rejecting it (#43197)

Thippaluri Yaseen Basha829cba1bf18c
diff --git a/litellm/llms/gemini/chat/transformation.py b/litellm/llms/gemini/chat/transformation.py
index 285350aecba..cae0ba49c3f 100644
--- a/litellm/llms/gemini/chat/transformation.py
+++ b/litellm/llms/gemini/chat/transformation.py
@@ -96,6 +96,7 @@ class GoogleAIStudioGeminiConfig(VertexGeminiConfig):
"logprobs",
"frequency_penalty",
"presence_penalty",
+ "seed",
"modalities",
"parallel_tool_calls",
"web_search_options",
diff --git a/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py b/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
index 7548f3c2daa..fd735afb16e 100644
--- a/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
+++ b/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
@@ -3413,6 +3413,34 @@ def test_google_ai_studio_presence_penalty_supported():
assert "presence_penalty" in supported_params
[email protected]("drop_params", [False, True])
+async def test_google_ai_studio_forwards_seed_to_generation_config(drop_params: bool):
+ def echo_seed_sent_upstream(request: httpx.Request) -> httpx.Response:
+ seed_sent: Final = json.loads(request.content).get("generationConfig", {}).get("seed")
+ return httpx.Response(
+ 200,
+ json={
+ "candidates": [
+ {"content": {"parts": [{"text": f"seed={seed_sent}"}], "role": "model"}, "finishReason": "STOP"}
+ ],
+ "usageMetadata": {"promptTokenCount": 1, "candidatesTokenCount": 1, "totalTokenCount": 2},
+ },
+ request=request,
+ )
+
+ response: Final = await litellm.acompletion(
+ model="gemini/gemini-3.8-flash",
+ messages=[{"role": "user", "content": "hi"}],
+ seed=42,
+ drop_params=drop_params,
+ api_key="fake-gemini-key",
+ client=AsyncHTTPHandler(transport=httpx.MockTransport(echo_seed_sent_upstream)),
+ )
+
+ assert response.choices[0].message.content == "seed=42"
+
+
# ==================== Tool Type Separation Tests ====================
# These tests verify that each Tool object contains exactly one type per Vertex AI API spec
# Ref: https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1beta1/Tool