From f7912990b76ee1305be2ae912493aa048edf1064 Mon Sep 17 00:00:00 2001 From: Cesar Garcia <128240629+Chesars@users.noreply.github.com> Date: Mon, 12 Jan 2026 08:42:19 -0300 Subject: [PATCH] fix(gemini): add presence_penalty support for Google AI Studio (#18154) Fixes #14753 Co-authored-by: Krish Dholakia --- litellm/llms/gemini/chat/transformation.py | 1 + .../test_vertex_and_google_ai_studio_gemini.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/litellm/llms/gemini/chat/transformation.py b/litellm/llms/gemini/chat/transformation.py index 62897fe6ecb..f6d075392b2 100644 --- a/litellm/llms/gemini/chat/transformation.py +++ b/litellm/llms/gemini/chat/transformation.py @@ -87,6 +87,7 @@ class GoogleAIStudioGeminiConfig(VertexGeminiConfig): "stop", "logprobs", "frequency_penalty", + "presence_penalty", "modalities", "parallel_tool_calls", "web_search_options", 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 5d91275fa8d..af76a5edda7 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 @@ -14,6 +14,7 @@ from litellm.llms.vertex_ai.common_utils import VertexAIError from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import ( VertexGeminiConfig, ) +from litellm.llms.gemini.chat.transformation import GoogleAIStudioGeminiConfig from litellm.types.llms.vertex_ai import UsageMetadata from litellm.types.utils import ChoiceLogprobs, Usage from litellm.utils import CustomStreamWrapper @@ -2315,6 +2316,17 @@ def test_partial_json_chunk_on_first_chunk(): assert iterator.chunk_type == "accumulated_json", "Should switch to accumulated_json mode" + +def test_google_ai_studio_presence_penalty_supported(): + """ + Test that presence_penalty is supported for Google AI Studio Gemini. + + Regression test for https://github.com/BerriAI/litellm/issues/14753 + """ + config = GoogleAIStudioGeminiConfig() + supported_params = config.get_supported_openai_params(model="gemini-2.0-flash") + + assert "presence_penalty" in supported_params # ==================== 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