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 d113b2b4f6b..1d224eb7649 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 @@ -878,9 +878,12 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): # Covers gemini-3-flash, gemini-3-flash-preview, gemini-3.1-flash, gemini-3.1-flash-lite-preview, # gemini-3.5-flash, and any future 3.x-flash variants. is_gemini3flash: Final = model and ("flash" in model.lower() and "gemini-3" in model.lower()) + requires_low_minimum_thinking: Final = model and ( + "gemini-3.7-flash" in model.lower() or "gemini-3.8-flash" in model.lower() + ) is_gemini31pro: Final = model and ("gemini-3.1-pro-preview" in model.lower()) if reasoning_effort == "minimal": - if is_gemini3flash: + if is_gemini3flash and not requires_low_minimum_thinking: return {"thinkingLevel": "minimal", "includeThoughts": True} else: return {"thinkingLevel": "low", "includeThoughts": True} @@ -895,13 +898,13 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): return {"thinkingLevel": "high", "includeThoughts": True} elif reasoning_effort == "disable": # Gemini 3 cannot fully disable thinking, so we use "minimal" for gemini-3-flash-preview, "low" for others - if is_gemini3flash: + if is_gemini3flash and not requires_low_minimum_thinking: return {"thinkingLevel": "minimal", "includeThoughts": False} else: return {"thinkingLevel": "low", "includeThoughts": False} elif reasoning_effort == "none": # For gemini-3-flash-preview, use "minimal" instead of "low" - if is_gemini3flash: + if is_gemini3flash and not requires_low_minimum_thinking: return {"thinkingLevel": "minimal", "includeThoughts": False} else: return {"thinkingLevel": "low", "includeThoughts": False} diff --git a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py index 101f6e6fa5d..986294d4b5f 100644 --- a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py +++ b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py @@ -2678,6 +2678,20 @@ def test_reasoning_effort_maps_to_thinking_level_gemini_3(): assert result["thinkingConfig"]["includeThoughts"] is False +@pytest.mark.parametrize("model", ["vertex_ai/gemini-3.7-flash", "vertex_ai/gemini-3.8-flash"]) +@pytest.mark.parametrize("reasoning_effort", ["minimal", "disable", "none"]) +def test_gemini_flash_uses_low_minimum_thinking_level(model: str, reasoning_effort: str): + result = VertexGeminiConfig().map_openai_params( + non_default_params={"reasoning_effort": reasoning_effort}, + optional_params={}, + model=model, + drop_params=False, + ) + + assert result["thinkingConfig"]["thinkingLevel"] == "low" + assert result["thinkingConfig"]["includeThoughts"] is (reasoning_effort == "minimal") + + def test_reasoning_effort_dict_format_gemini_3(): """ Test that reasoning_effort works when passed as dict format from OpenAI Agents SDK.