Grok CLI Manual

Use YAI Router

One config.toml connects Grok CLI to grok-4.6 and Imagine image/video tools through YAI Router and grok-cloud.

Copy a configuration with your Key filled in

Open the YAI 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.yairouter.com"
xai_api_base_url = "https://api.yairouter.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 YAI 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.toml

Skip the chmod command on Windows.

Verify the CLI

grok inspect
grok models
grok --model grok-4.6 --output-format json -p 'Reply with YAI_GROK_OK only'

Verify the Responses API

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

The CLI and API use the same YAI 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.