Grok CLI Manual
Use XAI Router
One config.toml connects Grok CLI to grok-4.6 and Imagine image/video tools through XAI Router and grok-cloud.
Copy a configuration with your Key filled in
Open the XAI Router configuration guide and find Grok CLI. The signed-in page inserts your current Key automatically, ready to copy.
The corresponding ~/.grok/config.toml structure is:
[models]
default = "grok-4.6"
[endpoints]
models_base_url = "https://api.xairouter.com"
xai_api_base_url = "https://api.xairouter.com"
[model."grok-4.6"]
model = "grok-4.6"
name = "Grok 4.6"
api_key = "sk-Xvs..."
api_backend = "responses"
context_window = 500000
supports_backend_search = true
[auth]
preferred_method = "api_key"
[session]
auto_compact_threshold_percent = 80
[ui]
max_thoughts_width = 120
yolo = true
compact_mode = false
permission_mode = "always-approve"models_base_url handles model discovery and primary inference requests; xai_api_base_url is used by image and video tools. Set both to the same XAI Router main API origin without /v1; direct API calls still use the standard /v1/... paths. Both paths use the same user Key, not a Grok OAuth refresh_token. preferred_method = "api_key" prevents an existing OAuth session from replacing the Router Key on Imagine-tool requests.
Restrict the file on Linux / macOS:
chmod 600 ~/.grok/config.tomlSkip the chmod command on Windows.
Verify the CLI
grok inspect
grok models
grok --model grok-4.6 --output-format json -p 'Reply with XAI_GROK_OK only'Verify the Responses API
curl https://api.xairouter.com/v1/responses \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-Xvs...' \
-d '{"model":"grok-4.6","input":"Reply with XAI_GROK_API_OK only"}'The CLI and API use the same XAI Router Key and main domain. See Image Generation and Editing and Video Generation for complete commands. context_window = 500000 follows the value on the xAI Grok 4.6 model page.