ExLLM.Adapters.XAI (ex_llm v0.5.0)
View SourceAdapter for X.AI's Grok models.
X.AI provides access to the Grok family of models including Grok-3, Grok-2, and their variants with different capabilities (vision, reasoning, etc.).
Configuration
The adapter requires an API key to be configured:
config :ex_llm, :xai,
api_key: System.get_env("XAI_API_KEY")
Or using environment variables:
XAI_API_KEY
- Your X.AI API key
Supported Models
grok-beta
- Grok Beta with 131K contextgrok-2-vision-1212
- Grok 2 with vision supportgrok-3-beta
- Grok 3 Beta with reasoning capabilitiesgrok-3-mini-beta
- Smaller, faster Grok 3 variant
See config/models/xai.yml
for the full list of models.
Features
- ✅ Streaming support
- ✅ Function calling
- ✅ Vision support (for vision models)
- ✅ Web search capabilities
- ✅ Structured outputs
- ✅ Tool choice
- ✅ Reasoning (Grok-3 models)
Example
# Basic chat
{:ok, response} = ExLLM.chat(:xai, [
%{role: "user", content: "What is the meaning of life?"}
])
# With vision
{:ok, response} = ExLLM.chat(:xai, [
%{
role: "user",
content: [
%{type: "text", text: "What's in this image?"},
%{type: "image_url", image_url: %{url: "data:image/jpeg;base64,..."}}
]
}
], model: "grok-2-vision-1212")
# Function calling
{:ok, response} = ExLLM.chat(:xai, messages,
model: "grok-beta",
tools: [weather_tool],
tool_choice: "auto"
)