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
Add support for OpenAI GPT-5.2 models (#17836)
Peter Dave Hello70643a8b9c36
diff --git a/docs/my-website/docs/providers/openai.md b/docs/my-website/docs/providers/openai.mdindex f1f88999d83..b170c6aba22 100644--- a/docs/my-website/docs/providers/openai.md+++ b/docs/my-website/docs/providers/openai.md@@ -188,6 +188,11 @@ os.environ["OPENAI_BASE_URL"] = "https://your_host/v1" # OPTIONAL| gpt-5-mini-2025-08-07 | `response = completion(model="gpt-5-mini-2025-08-07", messages=messages)` || gpt-5-nano-2025-08-07 | `response = completion(model="gpt-5-nano-2025-08-07", messages=messages)` || gpt-5-pro | `response = completion(model="gpt-5-pro", messages=messages)` |+| gpt-5.2 | `response = completion(model="gpt-5.2", messages=messages)` |+| gpt-5.2-2025-12-11 | `response = completion(model="gpt-5.2-2025-12-11", messages=messages)` |+| gpt-5.2-chat-latest | `response = completion(model="gpt-5.2-chat-latest", messages=messages)` |+| gpt-5.2-pro | `response = completion(model="gpt-5.2-pro", messages=messages)` |+| gpt-5.2-pro-2025-12-11 | `response = completion(model="gpt-5.2-pro-2025-12-11", messages=messages)` || gpt-5.1 | `response = completion(model="gpt-5.1", messages=messages)` || gpt-5.1-codex | `response = completion(model="gpt-5.1-codex", messages=messages)` || gpt-5.1-codex-mini | `response = completion(model="gpt-5.1-codex-mini", messages=messages)` |diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_5_transformation.pyindex a6d6b164366..1b3abb20d63 100644--- a/litellm/llms/openai/chat/gpt_5_transformation.py+++ b/litellm/llms/openai/chat/gpt_5_transformation.py@@ -34,12 +34,22 @@ class OpenAIGPT5Config(OpenAIGPTConfig):@classmethoddef is_model_gpt_5_1_model(cls, model: str) -> bool:- """Check if the model is a gpt-5.1 variant.+ """Check if the model is a gpt-5.1 or gpt-5.2 chat variant.- gpt-5.1 supports temperature when reasoning_effort="none",- unlike gpt-5 which only supports temperature=1.+ gpt-5.1/5.2 support temperature when reasoning_effort="none",+ unlike base gpt-5 which only supports temperature=1. Excludes+ pro variants which keep stricter knobs."""- return "gpt-5.1" in model+ model_name = model.split("/")[-1]+ is_gpt_5_1 = model_name.startswith("gpt-5.1")+ is_gpt_5_2 = model_name.startswith("gpt-5.2") and "pro" not in model_name+ return is_gpt_5_1 or is_gpt_5_2++ @classmethod+ def is_model_gpt_5_2_pro_model(cls, model: str) -> bool:+ """Check if the model is the gpt-5.2-pro snapshot/alias."""+ model_name = model.split("/")[-1]+ return model_name.startswith("gpt-5.2-pro")def get_supported_openai_params(self, model: str) -> list:from litellm.utils import supports_tool_choice@@ -77,7 +87,10 @@ class OpenAIGPT5Config(OpenAIGPTConfig):or optional_params.get("reasoning_effort"))if reasoning_effort is not None and reasoning_effort == "xhigh":- if not self.is_model_gpt_5_1_codex_max_model(model):+ if not (+ self.is_model_gpt_5_1_codex_max_model(model)+ or self.is_model_gpt_5_2_pro_model(model)+ ):if litellm.drop_params or drop_params:non_default_params.pop("reasoning_effort", None)else:diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex 03b36f09316..5fd7ff4a0cf 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -16300,6 +16300,176 @@"supports_tool_choice": false,"supports_vision": true},+ "gpt-5.2": {+ "cache_read_input_token_cost": 1.75e-07,+ "cache_read_input_token_cost_priority": 3.5e-07,+ "input_cost_per_token": 1.75e-06,+ "input_cost_per_token_priority": 3.5e-06,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "chat",+ "output_cost_per_token": 1.4e-05,+ "output_cost_per_token_priority": 2.8e-05,+ "supported_endpoints": [+ "/v1/chat/completions",+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text",+ "image"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_service_tier": true,+ "supports_vision": true+ },+ "gpt-5.2-2025-12-11": {+ "cache_read_input_token_cost": 1.75e-07,+ "cache_read_input_token_cost_priority": 3.5e-07,+ "input_cost_per_token": 1.75e-06,+ "input_cost_per_token_priority": 3.5e-06,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "chat",+ "output_cost_per_token": 1.4e-05,+ "output_cost_per_token_priority": 2.8e-05,+ "supported_endpoints": [+ "/v1/chat/completions",+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text",+ "image"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_service_tier": true,+ "supports_vision": true+ },+ "gpt-5.2-chat-latest": {+ "cache_read_input_token_cost": 1.75e-07,+ "cache_read_input_token_cost_priority": 3.5e-07,+ "input_cost_per_token": 1.75e-06,+ "input_cost_per_token_priority": 3.5e-06,+ "litellm_provider": "openai",+ "max_input_tokens": 128000,+ "max_output_tokens": 16384,+ "max_tokens": 16384,+ "mode": "chat",+ "output_cost_per_token": 1.4e-05,+ "output_cost_per_token_priority": 2.8e-05,+ "supported_endpoints": [+ "/v1/chat/completions",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },+ "gpt-5.2-pro": {+ "input_cost_per_token": 2.1e-05,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "responses",+ "output_cost_per_token": 1.68e-04,+ "supported_endpoints": [+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_vision": true,+ "supports_web_search": true+ },+ "gpt-5.2-pro-2025-12-11": {+ "input_cost_per_token": 2.1e-05,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "responses",+ "output_cost_per_token": 1.68e-04,+ "supported_endpoints": [+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_vision": true,+ "supports_web_search": true+ },"gpt-5-pro": {"input_cost_per_token": 1.5e-05,"input_cost_per_token_batches": 7.5e-06,diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex 03b36f09316..5fd7ff4a0cf 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -16300,6 +16300,176 @@"supports_tool_choice": false,"supports_vision": true},+ "gpt-5.2": {+ "cache_read_input_token_cost": 1.75e-07,+ "cache_read_input_token_cost_priority": 3.5e-07,+ "input_cost_per_token": 1.75e-06,+ "input_cost_per_token_priority": 3.5e-06,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "chat",+ "output_cost_per_token": 1.4e-05,+ "output_cost_per_token_priority": 2.8e-05,+ "supported_endpoints": [+ "/v1/chat/completions",+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text",+ "image"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_service_tier": true,+ "supports_vision": true+ },+ "gpt-5.2-2025-12-11": {+ "cache_read_input_token_cost": 1.75e-07,+ "cache_read_input_token_cost_priority": 3.5e-07,+ "input_cost_per_token": 1.75e-06,+ "input_cost_per_token_priority": 3.5e-06,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "chat",+ "output_cost_per_token": 1.4e-05,+ "output_cost_per_token_priority": 2.8e-05,+ "supported_endpoints": [+ "/v1/chat/completions",+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text",+ "image"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_service_tier": true,+ "supports_vision": true+ },+ "gpt-5.2-chat-latest": {+ "cache_read_input_token_cost": 1.75e-07,+ "cache_read_input_token_cost_priority": 3.5e-07,+ "input_cost_per_token": 1.75e-06,+ "input_cost_per_token_priority": 3.5e-06,+ "litellm_provider": "openai",+ "max_input_tokens": 128000,+ "max_output_tokens": 16384,+ "max_tokens": 16384,+ "mode": "chat",+ "output_cost_per_token": 1.4e-05,+ "output_cost_per_token_priority": 2.8e-05,+ "supported_endpoints": [+ "/v1/chat/completions",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_vision": true+ },+ "gpt-5.2-pro": {+ "input_cost_per_token": 2.1e-05,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "responses",+ "output_cost_per_token": 1.68e-04,+ "supported_endpoints": [+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_vision": true,+ "supports_web_search": true+ },+ "gpt-5.2-pro-2025-12-11": {+ "input_cost_per_token": 2.1e-05,+ "litellm_provider": "openai",+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "max_tokens": 128000,+ "mode": "responses",+ "output_cost_per_token": 1.68e-04,+ "supported_endpoints": [+ "/v1/batch",+ "/v1/responses"+ ],+ "supported_modalities": [+ "text",+ "image"+ ],+ "supported_output_modalities": [+ "text"+ ],+ "supports_function_calling": true,+ "supports_native_streaming": true,+ "supports_parallel_function_calling": true,+ "supports_pdf_input": true,+ "supports_prompt_caching": true,+ "supports_reasoning": true,+ "supports_response_schema": true,+ "supports_system_messages": true,+ "supports_tool_choice": true,+ "supports_vision": true,+ "supports_web_search": true+ },"gpt-5-pro": {"input_cost_per_token": 1.5e-05,"input_cost_per_token_batches": 7.5e-06,diff --git a/tests/test_litellm/llms/openai/test_gpt5_transformation.py b/tests/test_litellm/llms/openai/test_gpt5_transformation.pyindex 8b2c7fa27eb..4cb3132f737 100644--- a/tests/test_litellm/llms/openai/test_gpt5_transformation.py+++ b/tests/test_litellm/llms/openai/test_gpt5_transformation.py@@ -248,6 +248,10 @@ def test_gpt5_1_model_detection(gpt5_config: OpenAIGPT5Config):assert gpt5_config.is_model_gpt_5_1_model("gpt-5.1-codex")assert gpt5_config.is_model_gpt_5_1_model("gpt-5.1-codex-max")assert gpt5_config.is_model_gpt_5_1_model("gpt-5.1-chat")+ assert gpt5_config.is_model_gpt_5_1_model("gpt-5.2")+ assert gpt5_config.is_model_gpt_5_1_model("gpt-5.2-2025-12-11")+ assert gpt5_config.is_model_gpt_5_1_model("gpt-5.2-chat-latest")+ assert not gpt5_config.is_model_gpt_5_1_model("gpt-5.2-pro")assert not gpt5_config.is_model_gpt_5_1_model("gpt-5")assert not gpt5_config.is_model_gpt_5_1_model("gpt-5-mini")assert not gpt5_config.is_model_gpt_5_1_model("gpt-5-codex")@@ -267,6 +271,19 @@ def test_gpt5_1_temperature_with_reasoning_effort_none(config: OpenAIConfig):assert params["reasoning_effort"] == "none"+def test_gpt5_2_temperature_with_reasoning_effort_none(config: OpenAIConfig):+ """Test that GPT-5.2 aligns with GPT-5.1 temperature rules when effort='none'."""+ for temp in [0.0, 0.3, 0.7, 1.0, 1.5]:+ params = config.map_openai_params(+ non_default_params={"temperature": temp, "reasoning_effort": "none"},+ optional_params={},+ model="gpt-5.2",+ drop_params=False,+ )+ assert params["temperature"] == temp+ assert params["reasoning_effort"] == "none"++def test_gpt5_1_temperature_without_reasoning_effort(config: OpenAIConfig):"""Test that GPT-5.1 supports any temperature when reasoning_effort is not specified.@@ -359,3 +376,23 @@ def test_gpt5_temperature_still_restricted(config: OpenAIConfig):drop_params=False,)assert params["temperature"] == 1.0+++def test_gpt5_2_pro_allows_reasoning_effort_xhigh(config: OpenAIConfig):+ params = config.map_openai_params(+ non_default_params={"reasoning_effort": "xhigh"},+ optional_params={},+ model="gpt-5.2-pro",+ drop_params=False,+ )+ assert params["reasoning_effort"] == "xhigh"+++def test_gpt5_2_rejects_reasoning_effort_xhigh_for_base_model(config: OpenAIConfig):+ with pytest.raises(litellm.utils.UnsupportedParamsError):+ config.map_openai_params(+ non_default_params={"reasoning_effort": "xhigh"},+ optional_params={},+ model="gpt-5.2",+ drop_params=False,+ )