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
[Bug Fix] grok-4 does not support the `stop` param (#12646)
Ishaan Jaffe8a748161fae
diff --git a/litellm/llms/xai/chat/transformation.py b/litellm/llms/xai/chat/transformation.pyindex 14b62db41b3..5a488876cd9 100644--- a/litellm/llms/xai/chat/transformation.py+++ b/litellm/llms/xai/chat/transformation.py@@ -50,7 +50,7 @@ class XAIChatConfig(OpenAIGPTConfig):"web_search_options",]# for some reason, grok-3-mini does not support stop tokens- if "grok-3-mini" not in model:+ if self._supports_stop_reason(model):base_openai_params.append("stop")try:if litellm.supports_reasoning(@@ -61,6 +61,13 @@ class XAIChatConfig(OpenAIGPTConfig):verbose_logger.debug(f"Error checking if model supports reasoning: {e}")return base_openai_params++ def _supports_stop_reason(self, model: str) -> bool:+ if "grok-3-mini" in model:+ return False+ elif "grok-4" in model:+ return False+ return Truedef map_openai_params(self,diff --git a/tests/llm_translation/test_xai.py b/tests/llm_translation/test_xai.pyindex 41a39c79713..ba360d71788 100644--- a/tests/llm_translation/test_xai.py+++ b/tests/llm_translation/test_xai.py@@ -118,6 +118,21 @@ def test_xai_check_for_stop_in_supported_params():assert "stop" not in supported_params[email protected]("model", ["xai/grok-4", "xai/grok-4-0709"])+def test_xai_grok_4_stop_not_supported(model):+ """+ Test that grok-4 models do not support the stop parameter++ Issue: https://github.com/BerriAI/litellm/issues/12635+ """+ supported_params = XAIChatConfig().get_supported_openai_params(+ model=model+ )+ assert "stop" not in supported_params++++@pytest.mark.parametrize("stream", [False, True])def test_completion_xai(stream):try:@@ -130,9 +145,9 @@ def test_completion_xai(stream):},]response = completion(- model="xai/grok-3-mini-beta",+ model="xai/grok-4",messages=messages,- stream=stream,+ stream=stream)print(response)