From 7617d4e6dbe08f9002caf0a51abe3ab61090aa48 Mon Sep 17 00:00:00 2001 From: Mark McDonald Date: Tue, 24 Mar 2026 15:59:42 +0800 Subject: [PATCH] chore: add a service_tier field mapping from openai to gemini --- .../vertex_and_google_ai_studio_gemini.py | 13 ++++++++++++- .../test_vertex_and_google_ai_studio_gemini.py | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) 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 e854a85c5f8..bbb11394e1f 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 @@ -363,6 +363,17 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): """ return Tools(googleSearch={}) + def _map_service_tier_param(self, value: str, optional_params: dict) -> None: + """ + Map OpenAI service_tier (string) to Gemini serviceTier. + 'auto' maps to 'priority'. + Other values are passed blindly. + """ + if value == "auto": + optional_params["service_tier"] = "priority" + else: + optional_params["service_tier"] = value + def _transform_computer_use_config(self, computer_use_config: dict) -> dict: """ Transform Computer Use configuration to Gemini API format. @@ -1123,7 +1134,7 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): optional_params, [_tools] ) elif param == "service_tier" and isinstance(value, str): - optional_params["service_tier"] = value + self._map_service_tier_param(value, optional_params) elif param == "include_server_side_tool_invocations" and value is True: optional_params["include_server_side_tool_invocations"] = True if litellm.vertex_ai_safety_settings is not None: 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 416ea898c8b..7e1fff2fe2c 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 @@ -3674,18 +3674,33 @@ def test_vertex_ai_service_tier_in_map_openai_params(): ) v = VertexGeminiConfig() + + # Test pass-through optional_params = {} non_default_params = {"service_tier": "FLEX"} result = v.map_openai_params( non_default_params=non_default_params, optional_params=optional_params, - model="gemini-pro", + model="gemini-3-pro-preview", drop_params=True, ) assert result["service_tier"] == "FLEX" + # Test auto -> priority + optional_params_auto = {} + non_default_params_auto = {"service_tier": "auto"} + + result_auto = v.map_openai_params( + non_default_params=non_default_params_auto, + optional_params=optional_params_auto, + model="gemini-3-pro-preview", + drop_params=True, + ) + + assert result_auto["service_tier"] == "priority" + def test_vertex_ai_usage_metadata_with_video_tokens_in_prompt(): """Test promptTokensDetails with VIDEO modality for video inputs.