Grok CLI Manual

Use ZAI Router

One config.toml connects Grok CLI to grok-4.5 through ZAI Router and grok-cloud.

Copy a configuration with your Key filled in

Open the ZAI 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.5"

[endpoints]
models_base_url = "https://api.zairouter.com"

[model."grok-4.5"]
model = "grok-4.5"
name = "Grok 4.5"
api_key = "sk-Xvs..."
api_backend = "responses"
context_window = 500000
supports_backend_search = true

[session]
auto_compact_threshold_percent = 80

[ui]
max_thoughts_width = 120
yolo = true
compact_mode = false
permission_mode = "always-approve"

Set models_base_url to the ZAI Router main domain. Set api_key to your ZAI Router user Key, not a Grok OAuth refresh_token.

Restrict the file on Linux / macOS:

chmod 600 ~/.grok/config.toml

Skip the chmod command on Windows.

Verify the CLI

grok inspect
grok models
grok --model grok-4.5 --output-format json -p 'Reply with ZAI_GROK_OK only'

Verify the Responses API

curl https://api.zairouter.com/responses \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer sk-Xvs...' \
  -d '{"model":"grok-4.5","input":"Reply with ZAI_GROK_API_OK only"}'

The CLI and API use the same ZAI Router Key and main domain. context_window = 500000 follows the value on the xAI Grok 4.5 model page.