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]

refactor: replace substring check with startswith in is_model_gpt_5_model (#25793)

Braulio Vargas Lópezd26bcda52a03
diff --git a/litellm/llms/azure/chat/gpt_5_transformation.py b/litellm/llms/azure/chat/gpt_5_transformation.py
index bc7483bf64d..e94f50380c0 100644
--- a/litellm/llms/azure/chat/gpt_5_transformation.py
+++ b/litellm/llms/azure/chat/gpt_5_transformation.py
@@ -40,9 +40,22 @@ class AzureOpenAIGPT5Config(AzureOpenAIConfig, OpenAIGPT5Config):
Accepts both explicit gpt-5 model names and the ``gpt5_series/`` prefix
used for manual routing.
"""
- # gpt-5-chat* is a chat model and shouldn't go through GPT-5 reasoning restrictions.
+ # The gpt-5-chat* family (gpt-5-chat, gpt-5-chat-latest, gpt-5-chat-2025-08-07,
+ # …) are regular chat models: they support temperature and tool_choice but NOT
+ # reasoning_effort. They must NOT be routed through the GPT-5 reasoning path.
+ #
+ # Versioned chat models such as gpt-5.3-chat and gpt-5.1-chat ARE reasoning
+ # models and must stay on the GPT-5 path. The distinguishing feature is that
+ # the gpt-5-chat family has a literal "-chat" immediately after "gpt-5"
+ # (i.e. "gpt-5-chat…"), while versioned chat models interpose a minor version
+ # number (i.e. "gpt-5.<digit>-chat").
+ #
+ # Using a startswith("gpt-5-chat") prefix check on the normalized name (rather
+ # than a substring check) makes this boundary explicit and avoids any ambiguity
+ # if future model names coincidentally contain "gpt-5-chat" as an interior run.
+ _normalized = model.split("/")[-1] # strip provider prefix, e.g. "azure/"
return (
- "gpt-5" in model and "gpt-5-chat" not in model
+ "gpt-5" in model and not _normalized.startswith("gpt-5-chat")
) or "gpt5_series" in model
def get_supported_openai_params(self, model: str) -> List[str]:
diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_5_transformation.py
index fc48704cd10..34941a545eb 100644
--- a/litellm/llms/openai/chat/gpt_5_transformation.py
+++ b/litellm/llms/openai/chat/gpt_5_transformation.py
@@ -53,9 +53,21 @@ class OpenAIGPT5Config(OpenAIGPTConfig):
@classmethod
def is_model_gpt_5_model(cls, model: str) -> bool:
- # gpt-5-chat* behaves like a regular chat model (supports temperature, etc.)
- # Don't route it through GPT-5 reasoning-specific parameter restrictions.
- return "gpt-5" in model and "gpt-5-chat" not in model
+ # The gpt-5-chat* family (gpt-5-chat, gpt-5-chat-latest, gpt-5-chat-2025-08-07,
+ # …) are regular chat models: they support temperature and tool_choice but NOT
+ # reasoning_effort. They must NOT be routed through the GPT-5 reasoning path.
+ #
+ # Versioned chat models such as gpt-5.3-chat and gpt-5.1-chat ARE reasoning
+ # models and must stay on the GPT-5 path. The distinguishing feature is that
+ # the gpt-5-chat family has a literal "-chat" immediately after "gpt-5"
+ # (i.e. "gpt-5-chat…"), while versioned chat models interpose a minor version
+ # number (i.e. "gpt-5.<digit>-chat").
+ #
+ # Using a startswith("gpt-5-chat") prefix check on the normalized name (rather
+ # than a substring check) makes this boundary explicit and avoids any ambiguity
+ # if future model names coincidentally contain "gpt-5-chat" as an interior run.
+ _normalized = model.split("/")[-1] # strip provider prefix, e.g. "openai/"
+ return "gpt-5" in model and not _normalized.startswith("gpt-5-chat")
@classmethod
def is_model_gpt_5_search_model(cls, model: str) -> bool:
diff --git a/tests/test_litellm/llms/openai/test_is_model_gpt_5_model.py b/tests/test_litellm/llms/openai/test_is_model_gpt_5_model.py
new file mode 100644
index 00000000000..1d262872955
--- /dev/null
+++ b/tests/test_litellm/llms/openai/test_is_model_gpt_5_model.py
@@ -0,0 +1,151 @@
+"""
+Regression tests for is_model_gpt_5_model() in both OpenAI and Azure GPT-5 config
+classes.
+
+Background
+----------
+In v1.82.3 a substring check was introduced::
+
+ return "gpt-5" in model and "gpt-5-chat" not in model
+
+This inadvertently treated versioned chat models like ``gpt-5.3-chat`` and
+``gpt-5.1-chat`` as *non*-GPT-5 models, because the string ``"gpt-5-chat"`` is
+a substring of ``"gpt-5.3-chat"``. Those models were then routed through the
+regular Azure chat path which does not suppress ``parallel_tool_calls``, causing
+Azure to return ``finish_reason="stop"`` together with tool_calls and breaking
+n8n AI-agent workflows.
+
+There are two distinct families:
+
+* **gpt-5-chat family** (``gpt-5-chat``, ``gpt-5-chat-latest``,
+ ``gpt-5-chat-2025-08-07``, …) — regular chat models that support ``temperature``
+ and ``tool_choice`` but NOT ``reasoning_effort``. Must NOT be on the GPT-5
+ reasoning path.
+
+* **Versioned chat models** (``gpt-5.1-chat``, ``gpt-5.2-chat``,
+ ``gpt-5.3-chat``, …) — ARE GPT-5 reasoning models and must stay on the GPT-5
+ path.
+
+The fix uses a prefix check (``startswith("gpt-5-chat")``) on the normalised model
+name instead of a substring check, which correctly distinguishes the two families.
+"""
+
+import pytest
+
+from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config
+from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config
+
+# ---------------------------------------------------------------------------
+# Parametrized fixtures
+# ---------------------------------------------------------------------------
+
+# Models that MUST be classified as GPT-5 (routed through GPT-5 reasoning path)
+GPT5_MODELS = [
+ "gpt-5",
+ "gpt-5.1",
+ "gpt-5.2",
+ "gpt-5.3",
+ "gpt-5.4",
+ "gpt-5.1-chat", # versioned chat — THE KEY REGRESSION CASE
+ "gpt-5.2-chat", # versioned chat — also a regression case
+ "gpt-5.3-chat", # versioned chat — THE KEY REGRESSION CASE
+ "gpt-5.2-chat-latest", # versioned chat with date suffix
+ "gpt-5.1-codex",
+ "gpt-5.1-codex-mini",
+ "gpt-5.1-mini",
+ "gpt-5-nano",
+ "gpt-5-mini",
+ "gpt-5-codex",
+]
+
+# Models that must NOT be classified as GPT-5 (regular chat path)
+NON_GPT5_MODELS = [
+ "gpt-5-chat", # gpt-5-chat family — regular chat path
+ "gpt-5-chat-latest", # gpt-5-chat family with alias suffix
+ "gpt-5-chat-2025-08-07", # gpt-5-chat family with date suffix
+ "gpt-4",
+ "gpt-4o",
+ "gpt-4-turbo",
+ "gpt-3.5-turbo",
+ "o1",
+ "o3",
+ "o3-mini",
+]
+
+
+# ---------------------------------------------------------------------------
+# OpenAIGPT5Config
+# ---------------------------------------------------------------------------
+
+
+class TestOpenAIGPT5ConfigIsModelGpt5Model:
+
+ @pytest.mark.parametrize("model", GPT5_MODELS)
+ def test_gpt5_models_are_classified_as_gpt5(self, model: str):
+ assert OpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Expected '{model}' to be classified as a GPT-5 model"
+
+ @pytest.mark.parametrize("model", NON_GPT5_MODELS)
+ def test_non_gpt5_models_are_not_classified_as_gpt5(self, model: str):
+ assert not OpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Expected '{model}' NOT to be classified as a GPT-5 model"
+
+ def test_versioned_chat_models_are_not_excluded_by_prefix(self):
+ """Core regression guard: gpt-5-chat prefix must not match versioned models."""
+ versioned_chat_models = ["gpt-5.1-chat", "gpt-5.2-chat", "gpt-5.3-chat"]
+ for model in versioned_chat_models:
+ assert OpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Regression: '{model}' was incorrectly excluded from GPT-5 path"
+
+ def test_gpt5_chat_family_is_excluded(self):
+ """gpt-5-chat family should stay on the regular chat path."""
+ for model in ["gpt-5-chat", "gpt-5-chat-latest", "gpt-5-chat-2025-08-07"]:
+ assert not OpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Expected '{model}' (gpt-5-chat family) NOT to be on the GPT-5 path"
+
+
+# ---------------------------------------------------------------------------
+# AzureOpenAIGPT5Config
+# ---------------------------------------------------------------------------
+
+
+class TestAzureOpenAIGPT5ConfigIsModelGpt5Model:
+
+ @pytest.mark.parametrize("model", GPT5_MODELS)
+ def test_gpt5_models_are_classified_as_gpt5(self, model: str):
+ assert AzureOpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Expected Azure '{model}' to be classified as a GPT-5 model"
+
+ @pytest.mark.parametrize("model", NON_GPT5_MODELS)
+ def test_non_gpt5_models_are_not_classified_as_gpt5(self, model: str):
+ assert not AzureOpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Expected Azure '{model}' NOT to be classified as a GPT-5 model"
+
+ def test_versioned_chat_models_are_not_excluded_by_prefix(self):
+ """Core regression guard: gpt-5-chat prefix must not match versioned models."""
+ versioned_chat_models = ["gpt-5.1-chat", "gpt-5.2-chat", "gpt-5.3-chat"]
+ for model in versioned_chat_models:
+ assert AzureOpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Regression: Azure '{model}' was incorrectly excluded from GPT-5 path"
+
+ def test_gpt5_chat_family_is_excluded(self):
+ """gpt-5-chat family should stay on the regular chat path."""
+ for model in ["gpt-5-chat", "gpt-5-chat-latest", "gpt-5-chat-2025-08-07"]:
+ assert not AzureOpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Expected Azure '{model}' (gpt-5-chat family) NOT to be on the GPT-5 path"
+
+ def test_gpt5_series_routing_prefix_is_always_classified_as_gpt5(self):
+ """Models using the gpt5_series/ manual-routing prefix must always match."""
+ series_models = ["gpt5_series/my-deployment", "gpt5_series/prod"]
+ for model in series_models:
+ assert AzureOpenAIGPT5Config.is_model_gpt_5_model(
+ model
+ ), f"Azure '{model}' with gpt5_series/ prefix should be classified as GPT-5"