xAI (Grok)
Use xAI’s Grok models with cagent.
Overview
xAI provides the Grok family of models through an OpenAI-compatible API. cagent includes built-in support for xAI as an alias provider.
Setup
- Get an API key from xAI Console
-
Set the environment variable:
export XAI_API_KEY=your-api-key
Usage
Inline Syntax
The simplest way to use xAI:
agents:
root:
model: xai/grok-3
description: Assistant using Grok
instruction: You are a helpful assistant.
Named Model
For more control over parameters:
models:
grok:
provider: xai
model: grok-3
temperature: 0.7
max_tokens: 8192
agents:
root:
model: grok
description: Assistant using Grok
instruction: You are a helpful assistant.
Available Models
| Model | Description | Context |
|---|---|---|
grok-3 |
Latest and most capable Grok model | 131K |
grok-3-fast |
Faster variant with lower latency | 131K |
grok-3-mini |
Compact model for simpler tasks | 131K |
grok-3-mini-fast |
Fast variant of the mini model | 131K |
grok-2 |
Previous generation model | 128K |
grok-vision |
Vision-capable model | 32K |
Check the xAI documentation for the latest available models.
Extended Thinking
Grok models support thinking mode through the OpenAI-compatible API:
models:
grok:
provider: xai
model: grok-3
thinking_budget: high # minimal, low, medium, high, or none
How It Works
xAI is implemented as a built-in alias in cagent:
- API Type: OpenAI-compatible (
openai_chatcompletions) - Base URL:
https://api.x.ai/v1 - Token Variable:
XAI_API_KEY
Example: Research Assistant
agents:
researcher:
model: xai/grok-3
description: Research assistant with real-time knowledge
instruction: |
You are a research assistant using Grok.
Provide well-researched, factual responses.
Cite sources when available.
toolsets:
- type: mcp
ref: docker:duckduckgo
- type: think