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): add presence_penalty support for Google AI Studio (#18154)

Cesar Garciaf7912990b76e
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