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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(gemini): do not inject temperature for Gemini 3+ models when omitted (#45107)
Sukhdeep87478c7b6d6b
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.pyindex 93e0a183a2b..b6d27e80f02 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@@ -1299,11 +1299,6 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):elif "AUDIO" not in optional_params["responseModalities"]:optional_params["responseModalities"].append("AUDIO")- # Set default temperature to 1.0 for Gemini 3 models if not specified- if VertexGeminiConfig._is_gemini_3_or_newer(model):- if "temperature" not in optional_params:- optional_params["temperature"] = 1.0-self._drop_search_tools_mixed_with_functions(optional_params)return optional_paramsdiff --git a/tests/integration/providers/test_gemini_omitted_temperature.py b/tests/integration/providers/test_gemini_omitted_temperature.pynew file mode 100644index 00000000000..fa8a9c890c6--- /dev/null+++ b/tests/integration/providers/test_gemini_omitted_temperature.py@@ -0,0 +1,83 @@+"""A Gemini 3+ request that omits temperature reaches the provider without one: streamed on each endpoint, and in+a burst of mixed-endpoint requests spread across the proxy's workers."""++import json+from collections.abc import Mapping+from concurrent.futures import ThreadPoolExecutor+from typing import Final++import pytest+from integration._support.client import JSON_OBJECT, Gateway, object_value+from integration._support.provider import SharedProvider+from integration._support.wire import Reply, Request+from integration.translation.case import TranslationTestCase+from integration.translation.chat_completions.bases.gemini import (+ GEMINI_3_8_FLASH_TEST_CASE as CHAT_COMPLETIONS_TEST_CASE,+)+from integration.translation.messages.bases.gemini import GEMINI_3_8_FLASH_TEST_CASE as MESSAGES_TEST_CASE+from integration.translation.responses.bases.gemini import GEMINI_3_8_FLASH_TEST_CASE as RESPONSES_TEST_CASE+from pydantic import JsonValue++GENERATE_TARGET: Final = "/models/gemini-3.8-flash:generateContent"+STREAM_TARGET: Final = "/models/gemini-3.8-flash:streamGenerateContent?alt=sse"+EXPECTED_GENERATION_CONFIG: Final = {"max_output_tokens": 1024}+ENDPOINT_CASES: Final = (CHAT_COMPLETIONS_TEST_CASE, MESSAGES_TEST_CASE, RESPONSES_TEST_CASE)+BURST: Final = ENDPOINT_CASES * 4+STREAM_USAGE: Final = {+ "promptTokenCount": 10,+ "candidatesTokenCount": 2,+ "totalTokenCount": 12,+ "promptTokensDetails": [{"modality": "TEXT", "tokenCount": 10}],+}+++def _frame(payload: Mapping[str, JsonValue]) -> bytes:+ return f"data: {json.dumps(payload)}\n\n".encode()+++def _streamed_reply() -> Reply:+ opening: Final = {+ "candidates": [{"content": {"role": "model", "parts": [{"text": "Hello."}]}, "index": 0}],+ "modelVersion": "gemini-3.8-flash",+ "responseId": "stream-gemini-3-8-flash",+ }+ closing: Final = {+ "candidates": [{"content": {"role": "model", "parts": [{"text": ""}]}, "finishReason": "STOP", "index": 0}],+ "usageMetadata": STREAM_USAGE,+ "modelVersion": "gemini-3.8-flash",+ "responseId": "stream-gemini-3-8-flash",+ }+ return Reply(content_type="text/event-stream", chunks=(_frame(opening), _frame(closing)))+++def _generation_config(request: Request) -> dict[str, JsonValue]:+ return object_value(JSON_OBJECT.validate_json(request.body)["generationConfig"])++[email protected]("case", ENDPOINT_CASES, ids=lambda case: case.litellm_endpoint)+def test_streamed_request_without_temperature_forwards_none(+ case: TranslationTestCase, gateway: Gateway, provider: SharedProvider+) -> None:+ provider.expect(_streamed_reply())+ response: Final = gateway.request("POST", case.litellm_endpoint, {**case.litellm_request, "stream": True})+ assert response.status_code == 200, response.text+ assert "Hello." in response.text, response.text+ received: Final = provider.received()+ assert [(request.method, request.target) for request in received] == [("POST", STREAM_TARGET)]+ assert _generation_config(received[0]) == EXPECTED_GENERATION_CONFIG+++def test_concurrent_mixed_endpoint_burst_without_temperature_forwards_none(+ gateway: Gateway, provider: SharedProvider+) -> None:+ reply_body: Final = json.dumps(CHAT_COMPLETIONS_TEST_CASE.mock_provider_response).encode()+ provider.expect(*(Reply(body=reply_body) for _ in BURST))+ with ThreadPoolExecutor(max_workers=len(BURST)) as pool:+ responses: Final = tuple(+ pool.map(lambda case: gateway.request("POST", case.litellm_endpoint, case.litellm_request), BURST)+ )+ assert [response.status_code for response in responses] == [200] * len(BURST), [r.text for r in responses]+ assert all("Hello." in response.text for response in responses), [r.text for r in responses]+ received: Final = provider.received()+ assert [(request.method, request.target) for request in received] == [("POST", GENERATE_TARGET)] * len(BURST)+ assert [_generation_config(request) for request in received] == [EXPECTED_GENERATION_CONFIG] * len(BURST)diff --git a/tests/integration/translation/chat_completions/bases/gemini.py b/tests/integration/translation/chat_completions/bases/gemini.pyindex e9fbcb6ccda..1ffde32c3be 100644--- a/tests/integration/translation/chat_completions/bases/gemini.py+++ b/tests/integration/translation/chat_completions/bases/gemini.py@@ -21,7 +21,7 @@ GEMINI_3_5_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={@@ -97,7 +97,7 @@ GEMINI_3_8_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={@@ -173,7 +173,7 @@ GEMINI_3_1_PRO_PREVIEW_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={diff --git a/tests/integration/translation/chat_completions/bases/vertex_ai.py b/tests/integration/translation/chat_completions/bases/vertex_ai.pyindex 49018605bd1..236cefb5c72 100644--- a/tests/integration/translation/chat_completions/bases/vertex_ai.py+++ b/tests/integration/translation/chat_completions/bases/vertex_ai.py@@ -498,7 +498,7 @@ GEMINI_3_5_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [@@ -574,7 +574,7 @@ GEMINI_3_8_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [@@ -650,7 +650,7 @@ GEMINI_3_1_PRO_PREVIEW_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [diff --git a/tests/integration/translation/chat_completions/sampling/__init__.py b/tests/integration/translation/chat_completions/sampling/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/tests/integration/translation/chat_completions/sampling/test_chat_completions_sampling_gemini.py b/tests/integration/translation/chat_completions/sampling/test_chat_completions_sampling_gemini.pynew file mode 100644index 00000000000..1707fc71238--- /dev/null+++ b/tests/integration/translation/chat_completions/sampling/test_chat_completions_sampling_gemini.py@@ -0,0 +1,76 @@+from dataclasses import replace+from typing import Final++import pytest+from integration._support.client import Gateway, object_value+from integration._support.provider import SharedProvider+from integration.translation.case import TranslationTestCase+from integration.translation.chat_completions.bases.gemini import GEMINI_3_8_FLASH_TEST_CASE+from integration.translation.chat_completions.bases.vertex_ai import (+ GEMINI_3_8_FLASH_TEST_CASE as VERTEX_AI_GEMINI_3_8_FLASH_TEST_CASE,+)+from integration.translation.runner import assert_translation++GEMINI_GENERATION_CONFIG: Final = object_value(GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request["generationConfig"])+VERTEX_AI_GENERATION_CONFIG: Final = object_value(+ VERTEX_AI_GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request["generationConfig"]+)++GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE: Final = replace(+ GEMINI_3_8_FLASH_TEST_CASE,+ scenario="temperature",+ litellm_request={**GEMINI_3_8_FLASH_TEST_CASE.litellm_request, "temperature": 0.4},+ expected_provider_request={+ **GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request,+ "generationConfig": {**GEMINI_GENERATION_CONFIG, "temperature": 0.4},+ },+)++GEMINI_3_8_FLASH_ZERO_TEMPERATURE_TEST_CASE: Final = replace(+ GEMINI_3_8_FLASH_TEST_CASE,+ scenario="zero_temperature",+ litellm_request={**GEMINI_3_8_FLASH_TEST_CASE.litellm_request, "temperature": 0},+ expected_provider_request={+ **GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request,+ "generationConfig": {**GEMINI_GENERATION_CONFIG, "temperature": 0},+ },+)++GEMINI_3_8_FLASH_REASONING_EFFORT_TEST_CASE: Final = replace(+ GEMINI_3_8_FLASH_TEST_CASE,+ scenario="reasoning_effort",+ litellm_request={**GEMINI_3_8_FLASH_TEST_CASE.litellm_request, "reasoning_effort": "medium"},+ expected_provider_request={+ **GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request,+ "generationConfig": {+ **GEMINI_GENERATION_CONFIG,+ "thinkingConfig": {"thinkingLevel": "medium", "includeThoughts": True},+ },+ },+)++VERTEX_AI_GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE: Final = replace(+ VERTEX_AI_GEMINI_3_8_FLASH_TEST_CASE,+ scenario="temperature",+ litellm_request={**VERTEX_AI_GEMINI_3_8_FLASH_TEST_CASE.litellm_request, "temperature": 0.4},+ expected_provider_request={+ **VERTEX_AI_GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request,+ "generationConfig": {**VERTEX_AI_GENERATION_CONFIG, "temperature": 0.4},+ },+)+++ "case",+ [+ GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE,+ GEMINI_3_8_FLASH_ZERO_TEMPERATURE_TEST_CASE,+ GEMINI_3_8_FLASH_REASONING_EFFORT_TEST_CASE,+ VERTEX_AI_GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE,+ ],+ ids=lambda case: case.id,+)+def test_chat_completions_sampling_gemini(+ case: TranslationTestCase, gateway: Gateway, provider: SharedProvider+) -> None:+ assert_translation(case, gateway, provider)diff --git a/tests/integration/translation/messages/bases/gemini.py b/tests/integration/translation/messages/bases/gemini.pyindex 217a9960b6e..b464f9a686e 100644--- a/tests/integration/translation/messages/bases/gemini.py+++ b/tests/integration/translation/messages/bases/gemini.py@@ -18,7 +18,7 @@ GEMINI_3_5_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={@@ -72,7 +72,7 @@ GEMINI_3_8_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={@@ -126,7 +126,7 @@ GEMINI_3_1_PRO_PREVIEW_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={diff --git a/tests/integration/translation/messages/bases/vertex_ai.py b/tests/integration/translation/messages/bases/vertex_ai.pyindex 97d48bdc871..be1765f5d26 100644--- a/tests/integration/translation/messages/bases/vertex_ai.py+++ b/tests/integration/translation/messages/bases/vertex_ai.py@@ -379,7 +379,7 @@ GEMINI_3_5_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [@@ -433,7 +433,7 @@ GEMINI_3_8_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [@@ -487,7 +487,7 @@ GEMINI_3_1_PRO_PREVIEW_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [diff --git a/tests/integration/translation/messages/sampling/__init__.py b/tests/integration/translation/messages/sampling/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/tests/integration/translation/messages/sampling/test_messages_sampling_gemini.py b/tests/integration/translation/messages/sampling/test_messages_sampling_gemini.pynew file mode 100644index 00000000000..e2b54774b1b--- /dev/null+++ b/tests/integration/translation/messages/sampling/test_messages_sampling_gemini.py@@ -0,0 +1,26 @@+from dataclasses import replace+from typing import Final++import pytest+from integration._support.client import Gateway, object_value+from integration._support.provider import SharedProvider+from integration.translation.case import TranslationTestCase+from integration.translation.messages.bases.gemini import GEMINI_3_8_FLASH_TEST_CASE+from integration.translation.runner import assert_translation++GENERATION_CONFIG: Final = object_value(GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request["generationConfig"])++GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE: Final = replace(+ GEMINI_3_8_FLASH_TEST_CASE,+ scenario="temperature",+ litellm_request={**GEMINI_3_8_FLASH_TEST_CASE.litellm_request, "temperature": 0.4},+ expected_provider_request={+ **GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request,+ "generationConfig": {**GENERATION_CONFIG, "temperature": 0.4},+ },+)++[email protected]("case", [GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE], ids=lambda case: case.id)+def test_messages_sampling_gemini(case: TranslationTestCase, gateway: Gateway, provider: SharedProvider) -> None:+ assert_translation(case, gateway, provider)diff --git a/tests/integration/translation/responses/bases/gemini.py b/tests/integration/translation/responses/bases/gemini.pyindex 3b72eb4ff00..34591a31843 100644--- a/tests/integration/translation/responses/bases/gemini.py+++ b/tests/integration/translation/responses/bases/gemini.py@@ -19,7 +19,7 @@ GEMINI_3_5_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={@@ -110,7 +110,7 @@ GEMINI_3_8_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={@@ -201,7 +201,7 @@ GEMINI_3_1_PRO_PREVIEW_TEST_CASE: Final = TranslationTestCase(expected_provider_headers={"content-type": "application/json", "x-goog-api-key": "synthetic-gemini-key"},expected_provider_request={"contents": [{"parts": [{"text": "Say hello."}], "role": "user"}],- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},},mock_provider_response={diff --git a/tests/integration/translation/responses/bases/vertex_ai.py b/tests/integration/translation/responses/bases/vertex_ai.pyindex eb0bf46e9db..de2ac6fdd68 100644--- a/tests/integration/translation/responses/bases/vertex_ai.py+++ b/tests/integration/translation/responses/bases/vertex_ai.py@@ -592,7 +592,7 @@ GEMINI_3_5_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [@@ -684,7 +684,7 @@ GEMINI_3_8_FLASH_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [@@ -776,7 +776,7 @@ GEMINI_3_1_PRO_PREVIEW_TEST_CASE: Final = TranslationTestCase(expected_provider_request={"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}],"system_instruction": {"parts": [{"text": "You are a terse assistant."}]},- "generationConfig": {"max_output_tokens": 1024, "temperature": 1.0},+ "generationConfig": {"max_output_tokens": 1024},},mock_provider_response={"candidates": [diff --git a/tests/integration/translation/responses/sampling/__init__.py b/tests/integration/translation/responses/sampling/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/tests/integration/translation/responses/sampling/test_responses_sampling_gemini.py b/tests/integration/translation/responses/sampling/test_responses_sampling_gemini.pynew file mode 100644index 00000000000..6e82132aecb--- /dev/null+++ b/tests/integration/translation/responses/sampling/test_responses_sampling_gemini.py@@ -0,0 +1,27 @@+from dataclasses import replace+from typing import Final++import pytest+from integration._support.client import Gateway, object_value+from integration._support.provider import SharedProvider+from integration.translation.case import TranslationTestCase+from integration.translation.responses.bases.gemini import GEMINI_3_8_FLASH_TEST_CASE+from integration.translation.runner import assert_translation++GENERATION_CONFIG: Final = object_value(GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request["generationConfig"])++GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE: Final = replace(+ GEMINI_3_8_FLASH_TEST_CASE,+ scenario="temperature",+ litellm_request={**GEMINI_3_8_FLASH_TEST_CASE.litellm_request, "temperature": 0.4},+ expected_provider_request={+ **GEMINI_3_8_FLASH_TEST_CASE.expected_provider_request,+ "generationConfig": {**GENERATION_CONFIG, "temperature": 0.4},+ },+ expected_litellm_response={**GEMINI_3_8_FLASH_TEST_CASE.expected_litellm_response, "temperature": 0.4},+)++[email protected]("case", [GEMINI_3_8_FLASH_TEMPERATURE_TEST_CASE], ids=lambda case: case.id)+def test_responses_sampling_gemini(case: TranslationTestCase, gateway: Gateway, provider: SharedProvider) -> None:+ assert_translation(case, gateway, provider)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.pyindex fb92cb39f33..6f65c48c228 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@@ -2,7 +2,7 @@ import asyncio, importlib, os, uuidimport jsonimport refrom copy import deepcopy-from typing import Final, List, cast, get_args+from typing import Final, List, Literal, cast, get_argsfrom unittest.mock import MagicMock, Mock, patchimport httpx@@ -3013,7 +3013,7 @@ def test_is_gemini_3_or_newer():],)def test_gemini_3_reasoning_effort_maps_to_thinking_level(model: str):- """Test that reasoning_effort maps to thinkingLevel and default temperature=1.0"""+ """Test that reasoning_effort maps to thinkingLevel and no temperature is injected"""from litellm.llms.gemini.chat.transformation import GoogleAIStudioGeminiConfigfrom litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (VertexGeminiConfig,@@ -3038,7 +3038,7 @@ def test_gemini_3_reasoning_effort_maps_to_thinking_level(model: str):"thinkingLevel": effort,"includeThoughts": True,}- assert mapped["temperature"] == 1.0+ assert "temperature" not in mappedassert "thinkingBudget" not in mapped["thinkingConfig"]@@ -3473,28 +3473,58 @@ def test_reasoning_effort_dict_format_gemini_3():assert "thinkingConfig" not in result-def test_temperature_default_for_gemini_3():- """Test that temperature defaults to 1.0 for Gemini 3+ models when not specified"""[email protected]("model", ["gemini-3-pro-preview", "gemini-flash-latest"])[email protected]("config_cls", ["vertex", "studio"])+def test_gemini_3_omits_temperature_when_not_specified(model: str, config_cls: Literal["vertex", "studio"]) -> None:+ """Gemini 3+ requests must not gain a temperature the caller did not send"""from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (VertexGeminiConfig,)- v = VertexGeminiConfig()- model = "gemini-3-pro-preview"- optional_params = {}-- # No temperature specified- non_default_params = {}- result = v.map_openai_params(- non_default_params=non_default_params,- optional_params=optional_params,+ cfg: Final = VertexGeminiConfig() if config_cls == "vertex" else GoogleAIStudioGeminiConfig()+ result: Final = cfg.map_openai_params(+ non_default_params={},+ optional_params={},model=model,drop_params=False,)- # Should default to 1.0- assert "temperature" in result- assert result["temperature"] == 1.0+ assert "temperature" not in result++[email protected]("config_cls", ["vertex", "studio"])+def test_gemini_3_explicit_temperature_is_still_forwarded(config_cls: Literal["vertex", "studio"]) -> None:+ """An explicitly supplied temperature is still forwarded"""+ from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (+ VertexGeminiConfig,+ )++ cfg: Final = VertexGeminiConfig() if config_cls == "vertex" else GoogleAIStudioGeminiConfig()+ result: Final = cfg.map_openai_params(+ non_default_params={"temperature": 0.4},+ optional_params={},+ model="gemini-3-pro-preview",+ drop_params=False,+ )++ assert result["temperature"] == 0.4++[email protected]("custom_llm_provider", ["gemini", "vertex_ai"])+def test_get_optional_params_gemini_3_has_no_default_temperature(+ custom_llm_provider: Literal["gemini", "vertex_ai"],+) -> None:+ """Neither the gemini nor the vertex_ai route injects a temperature"""+ from litellm.utils import get_optional_params++ optional_params: Final = get_optional_params(+ model="gemini-3-pro-preview",+ custom_llm_provider=custom_llm_provider,+ reasoning_effort="medium",+ )++ assert "temperature" not in optional_params+ assert optional_params["thinkingConfig"]["thinkingLevel"] == "medium"def test_media_resolution_from_detail_parameter():@@ -3744,8 +3774,7 @@ def test_gemini_3_image_models_no_thinking_config():# Should NOT have thinkingConfig automatically addedassert "thinkingConfig" not in result- # But should still get temperature=1.0 for Gemini 3- assert result["temperature"] == 1.0+ assert "temperature" not in resultdef test_gemini_3_text_models_get_thinking_config():@@ -3773,7 +3802,7 @@ def test_gemini_3_text_models_get_thinking_config():# Should NOT have thinkingConfig automatically added when user provides no reasoning_effortassert "thinkingConfig" not in result- assert result["temperature"] == 1.0+ assert "temperature" not in resultdef test_gemini_image_models_excluded_from_thinking():