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]

Fixed grok-3-mini to not use stop tokens (#11563)

nevinb7cb66ee8f66
diff --git a/litellm/llms/xai/chat/transformation.py b/litellm/llms/xai/chat/transformation.py
index c277b9623c5..272e3841eb6 100644
--- a/litellm/llms/xai/chat/transformation.py
+++ b/litellm/llms/xai/chat/transformation.py
@@ -36,7 +36,6 @@ class XAIChatConfig(OpenAIGPTConfig):
"presence_penalty",
"response_format",
"seed",
- "stop",
"stream",
"stream_options",
"temperature",
@@ -47,6 +46,9 @@ class XAIChatConfig(OpenAIGPTConfig):
"user",
"web_search_options",
]
+ # for some reason, grok-3-mini does not support stop tokens
+ if "grok-3-mini" not in model:
+ base_openai_params.append("stop")
try:
if litellm.supports_reasoning(
model=model, custom_llm_provider=self.custom_llm_provider
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index 18b0326248b..aee45b4c429 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -4442,6 +4442,20 @@
"source": "https://x.ai/api#pricing",
"supports_web_search": true
},
+ "xai/grok-3-latest": {
+ "max_tokens": 131072,
+ "max_input_tokens": 131072,
+ "max_output_tokens": 131072,
+ "input_cost_per_token": 3e-06,
+ "output_cost_per_token": 1.5e-05,
+ "litellm_provider": "xai",
+ "mode": "chat",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_response_schema": false,
+ "source": "https://x.ai/api#pricing",
+ "supports_web_search": true
+ },
"xai/grok-3-beta": {
"max_tokens": 131072,
"max_input_tokens": 131072,
@@ -4484,6 +4498,66 @@
"source": "https://x.ai/api#pricing",
"supports_web_search": true
},
+ "xai/grok-3-mini": {
+ "max_tokens": 131072,
+ "max_input_tokens": 131072,
+ "max_output_tokens": 131072,
+ "input_cost_per_token": 3e-07,
+ "output_cost_per_token": 5e-07,
+ "litellm_provider": "xai",
+ "mode": "chat",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_response_schema": false,
+ "source": "https://x.ai/api#pricing",
+ "supports_web_search": true
+ },
+ "xai/grok-3-mini-latest": {
+ "max_tokens": 131072,
+ "max_input_tokens": 131072,
+ "max_output_tokens": 131072,
+ "input_cost_per_token": 3e-07,
+ "output_cost_per_token": 5e-07,
+ "litellm_provider": "xai",
+ "mode": "chat",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_response_schema": false,
+ "source": "https://x.ai/api#pricing",
+ "supports_web_search": true
+ },
+ "xai/grok-3-mini-fast": {
+ "max_tokens": 131072,
+ "max_input_tokens": 131072,
+ "max_output_tokens": 131072,
+ "input_cost_per_token": 6e-07,
+ "output_cost_per_token": 4e-06,
+ "litellm_provider": "xai",
+ "mode": "chat",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_response_schema": false,
+ "source": "https://x.ai/api#pricing",
+ "supports_web_search": true
+ },
+ "xai/grok-3-mini-fast-latest": {
+ "max_tokens": 131072,
+ "max_input_tokens": 131072,
+ "max_output_tokens": 131072,
+ "input_cost_per_token": 6e-07,
+ "output_cost_per_token": 4e-06,
+ "litellm_provider": "xai",
+ "mode": "chat",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_response_schema": false,
+ "source": "https://x.ai/api#pricing",
+ "supports_web_search": true
+ },
"xai/grok-3-mini-beta": {
"max_tokens": 131072,
"max_input_tokens": 131072,
diff --git a/tests/llm_translation/test_xai.py b/tests/llm_translation/test_xai.py
index 648ae2b15bd..df5d1ddffb1 100644
--- a/tests/llm_translation/test_xai.py
+++ b/tests/llm_translation/test_xai.py
@@ -111,6 +111,14 @@ def test_xai_chat_config_map_openai_params():
# Assert unsupported parameter is not in the result
assert "unsupported_param" not in result
+ # Test 'grok-3-mini' variants, as xAI does not support stop tokens on them.
+ # See PR #11563: https://github.com/BerriAI/litellm/pull/11563
+ model = "xai/grok-3-mini"
+
+ result = config.map_openai_params(non_default_params, optional_params, model)
+
+ assert "stop" not in result
+
@pytest.mark.parametrize("stream", [False, True])
def test_completion_xai(stream):