xAI
xAI builds the Grok models; LiteLLM calls every xAI model with the xai/ prefix from the Python SDK or AI Gateway, with streaming, vision and reasoning.
We support ALL xAI models, just set model=xai/<any-model-on-xai> as a prefix when sending litellm requests
Supported Models
Grok 4.5 - Frontier model for coding, agentic tasks, and knowledge work with 500K context, reasoning (low/medium/high), vision, tools, web search, and prompt caching.
| Model | Context | Features |
|---|---|---|
xai/grok-4.5 | 500K tokens | Reasoning, Function calling, Vision, Web search, Caching |
Example:
from litellm import completion
response = completion(
model="xai/grok-4.5",
messages=[{"role": "user", "content": "Find and fix the bug, then explain it."}],
reasoning_effort="high", # low | medium | high (default high)
)
Features:
- Reasoning = Chain-of-thought reasoning with reasoning tokens
- Tools = Function calling / Tool use
- Web search = Live internet search
- Vision = Image understanding
- Caching = Prompt caching for cost savings
- Structured outputs = JSON / schema-constrained responses
Pricing: See xAI's pricing page for current rates.
API Key
# env variable
os.environ['XAI_API_KEY']
Latest model aliases
Since v1.109.0xai/<family>-latest names follow a model family as LiteLLM moves them to newer models, so your application keeps one model string. Use them like any other xAI model name. LiteLLM sends xAI the current target model and bills at that model's price. See Latest model aliases for how aliases work and the full list across providers.
| Alias | Model family |
|---|---|
xai/grok-latest | Grok |
Sample Usage
from litellm import completion
import os
os.environ['XAI_API_KEY'] = ""
response = completion(
model="xai/grok-4.5",
messages=[
{
"role": "user",
"content": "What's the weather like in Boston today in Fahrenheit?",
}
],
max_tokens=10,
response_format={ "type": "json_object" },
seed=123,
temperature=0.2,
top_p=0.9,
tool_choice="auto",
tools=[],
user="user",
)
print(response)
Sample Usage - Streaming
from litellm import completion
import os
os.environ['XAI_API_KEY'] = ""
response = completion(
model="xai/grok-4.5",
messages=[
{
"role": "user",
"content": "What's the weather like in Boston today in Fahrenheit?",
}
],
stream=True,
max_tokens=10,
response_format={ "type": "json_object" },
seed=123,
temperature=0.2,
top_p=0.9,
tool_choice="auto",
tools=[],
user="user",
)
for chunk in response:
print(chunk)
Sample Usage - Vision
import os
from litellm import completion
os.environ["XAI_API_KEY"] = "your-api-key"
response = completion(
model="xai/grok-4.5",
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://science.nasa.gov/wp-content/uploads/2023/09/web-first-images-release.png",
"detail": "high",
},
},
{
"type": "text",
"text": "What's in this image?",
},
],
},
],
)