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]

fix(xai): accept max_completion_tokens as a supported param

kerry5c0589207cb1
diff --git a/litellm/llms/xai/chat/transformation.py b/litellm/llms/xai/chat/transformation.py
index 91bf697487d..33ee727dfab 100644
--- a/litellm/llms/xai/chat/transformation.py
+++ b/litellm/llms/xai/chat/transformation.py
@@ -118,6 +118,7 @@ class XAIChatConfig(OpenAIGPTConfig):
base_openai_params: Final = [
"logit_bias",
"logprobs",
+ "max_completion_tokens",
"max_tokens",
"n",
"parallel_tool_calls",
diff --git a/tests/test_litellm/llms/xai/test_xai_chat_transformation.py b/tests/test_litellm/llms/xai/test_xai_chat_transformation.py
index 290cd3dcb3a..3fd666e4f50 100644
--- a/tests/test_litellm/llms/xai/test_xai_chat_transformation.py
+++ b/tests/test_litellm/llms/xai/test_xai_chat_transformation.py
@@ -90,6 +90,16 @@ class TestXAIReasoningTokenFolding:
assert response.usage.total_tokens == 999
+def test_max_completion_tokens_is_accepted_and_mapped_to_max_tokens() -> None:
+ optional_params = litellm.get_optional_params(
+ model="grok-4.20",
+ custom_llm_provider="xai",
+ max_completion_tokens=64,
+ )
+ assert optional_params["max_tokens"] == 64, optional_params
+ assert "max_completion_tokens" not in optional_params, optional_params
+
+
class TestXAIParallelToolCalls:
"""Test suite for XAI parallel tool calls functionality."""