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] Support service_tier in chat completion (#15693)
katsuhiro mutod5e686b3e8e5
diff --git a/litellm/constants.py b/litellm/constants.pyindex cf6b53fb3e9..64e92e382f8 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -399,6 +399,7 @@ OPENAI_CHAT_COMPLETION_PARAMS = ["extra_headers","thinking","web_search_options",+ "service_tier",]OPENAI_TRANSCRIPTION_PARAMS = [@@ -453,6 +454,7 @@ DEFAULT_CHAT_COMPLETION_PARAM_VALUES = {"reasoning_effort": None,"thinking": None,"web_search_options": None,+ "service_tier": None,"safety_identifier": None,}diff --git a/litellm/llms/openai/chat/gpt_transformation.py b/litellm/llms/openai/chat/gpt_transformation.pyindex 3e18617905c..4e553a3da5c 100644--- a/litellm/llms/openai/chat/gpt_transformation.py+++ b/litellm/llms/openai/chat/gpt_transformation.py@@ -158,6 +158,7 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):"parallel_tool_calls","audio","web_search_options",+ "service_tier","safety_identifier",] # works across all modelsdiff --git a/litellm/main.py b/litellm/main.pyindex a1975f3a0f5..5000de7a694 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -380,6 +380,7 @@ async def acompletion(Literal["none", "minimal", "low", "medium", "high", "default"]] = None,safety_identifier: Optional[str] = None,+ service_tier: Optional[str] = None,# set api_base, api_version, api_keybase_url: Optional[str] = None,api_version: Optional[str] = None,@@ -529,6 +530,7 @@ async def acompletion("model_list": model_list,"reasoning_effort": reasoning_effort,"safety_identifier": safety_identifier,+ "service_tier": service_tier,"extra_headers": extra_headers,"acompletion": True, # assuming this is a required parameter"thinking": thinking,@@ -951,6 +953,7 @@ def completion( # type: ignore # noqa: PLR0915deployment_id=None,extra_headers: Optional[dict] = None,safety_identifier: Optional[str] = None,+ service_tier: Optional[str] = None,# soon to be deprecated params by OpenAIfunctions: Optional[List] = None,function_call: Optional[str] = None,@@ -1293,6 +1296,7 @@ def completion( # type: ignore # noqa: PLR0915"thinking": thinking,"web_search_options": web_search_options,"safety_identifier": safety_identifier,+ "service_tier": service_tier,"allowed_openai_params": kwargs.get("allowed_openai_params"),}optional_params = get_optional_params(diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex d7e261cf23c..c6f8275a6a1 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -12520,6 +12520,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-2025-04-14": {@@ -12553,6 +12554,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-mini": {@@ -12589,6 +12591,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-mini-2025-04-14": {@@ -12622,6 +12625,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-nano": {@@ -12658,6 +12662,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-nano-2025-04-14": {@@ -12691,6 +12696,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.5-preview": {@@ -12755,6 +12761,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-2024-05-13": {@@ -12795,6 +12802,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-2024-11-20": {@@ -12815,6 +12823,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-audio-preview": {@@ -12906,6 +12915,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-mini-2024-07-18": {@@ -12931,6 +12941,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-mini-audio-preview": {@@ -13248,6 +13259,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-5-pro": {@@ -13485,6 +13497,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-5-mini-2025-08-07": {@@ -13523,6 +13536,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-5-nano": {@@ -16543,6 +16557,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o3-2025-04-16": {@@ -16574,6 +16589,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o3-deep-research": {@@ -16758,6 +16774,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o4-mini-2025-04-16": {@@ -16776,6 +16793,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o4-mini-deep-research": {diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex d7e261cf23c..c6f8275a6a1 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -12520,6 +12520,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-2025-04-14": {@@ -12553,6 +12554,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-mini": {@@ -12589,6 +12591,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-mini-2025-04-14": {@@ -12622,6 +12625,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-nano": {@@ -12658,6 +12662,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.1-nano-2025-04-14": {@@ -12691,6 +12696,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4.5-preview": {@@ -12755,6 +12761,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-2024-05-13": {@@ -12795,6 +12802,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-2024-11-20": {@@ -12815,6 +12823,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-audio-preview": {@@ -12906,6 +12915,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-mini-2024-07-18": {@@ -12931,6 +12941,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-4o-mini-audio-preview": {@@ -13248,6 +13259,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-5-pro": {@@ -13485,6 +13497,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-5-mini-2025-08-07": {@@ -13523,6 +13536,7 @@"supports_response_schema": true,"supports_system_messages": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"gpt-5-nano": {@@ -16543,6 +16557,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o3-2025-04-16": {@@ -16574,6 +16589,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o3-deep-research": {@@ -16758,6 +16774,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o4-mini-2025-04-16": {@@ -16776,6 +16793,7 @@"supports_reasoning": true,"supports_response_schema": true,"supports_tool_choice": true,+ "supports_service_tier": true,"supports_vision": true},"o4-mini-deep-research": {diff --git a/tests/llm_translation/test_openai.py b/tests/llm_translation/test_openai.pyindex 15bb5fec66d..716a679f484 100644--- a/tests/llm_translation/test_openai.py+++ b/tests/llm_translation/test_openai.py@@ -728,6 +728,65 @@ def test_openai_safety_identifier_parameter_sync():assert request_body["safety_identifier"] == "user_code_123456"+async def test_openai_service_tier_parameter():+ """Test that service_tier parameter is correctly passed to the OpenAI API."""+ from openai import AsyncOpenAI++ litellm.set_verbose = True+ client = AsyncOpenAI(api_key="fake-api-key")++ with patch.object(+ client.chat.completions.with_raw_response, "create"+ ) as mock_client:+ try:+ await litellm.acompletion(+ model="openai/gpt-4o",+ messages=[{"role": "user", "content": "Hello, how are you?"}],+ service_tier="priority",+ client=client,+ )+ except Exception as e:+ print(f"Error: {e}")++ mock_client.assert_called_once()+ request_body = mock_client.call_args.kwargs++ # Verify the request contains the service_tier parameter+ assert "service_tier" in request_body, "service_tier should be in request body"+ # Verify service_tier is correctly sent to the API+ assert request_body["service_tier"] == "priority", "service_tier should be 'priority'"+++def test_openai_service_tier_parameter_sync():+ """Test that service_tier parameter is correctly passed to the OpenAI API."""+ from openai import OpenAI++ litellm.set_verbose = True+ client = OpenAI(api_key="fake-api-key")++ with patch.object(+ client.chat.completions.with_raw_response, "create"+ ) as mock_client:+ try:+ litellm.completion(+ model="openai/gpt-4o",+ messages=[{"role": "user", "content": "Hello, how are you?"}],+ service_tier="priority",+ client=client,+ )+ except Exception as e:+ print(f"Error: {e}")++ mock_client.assert_called_once()+ request_body = mock_client.call_args.kwargs++ # Verify the request contains the service_tier parameter+ assert "service_tier" in request_body, "service_tier should be in request body"+ # Verify service_tier is correctly sent to the API+ assert request_body["service_tier"] == "priority", "service_tier should be 'priority'"++def test_gpt_5_reasoning_streaming():litellm._turn_on_debug()response = litellm.completion(