Skip to main content

Overview

Grok Build is xAI’s official CLI assistant. It supports custom OpenAI-compatible endpoints via ~/.grok/config.toml, so any model in the AI Gateway catalog can be reached from a single config entry without changing tooling.

Prerequisites

Install Grok Build

curl -fsSL https://x.ai/cli/install.sh | bash
The installer places grok and agent in ~/.grok/bin/ and updates the user PATH.

Setup

1

Edit ~/.grok/config.toml

Configure models with a [models] section and one [model.<key>] block per model. The example below uses Claude Sonnet 4.6 routed through Orq.ai:
[models]
default = "orq-claude"

[model.orq-claude]
model = "anthropic/claude-sonnet-4-6"
base_url = "https://api.orq.ai/v3/router"
env_key = "ORQ_API_KEY"
name = "Claude Sonnet 4.6 via Orq"
context_window = 200000
max_completion_tokens = 8192
Replace anthropic/claude-sonnet-4-6 with any model identifier from the AI Gateway catalog. To register additional models, add more [model.<key>] blocks and switch between them with -m <key>.
2

Export the API key

export ORQ_API_KEY="<orq-api-key>"
Replace <orq-api-key> with the key from Organization > API Keys. The env_key field in config.toml tells Grok Build which environment variable to read.
3

Launch Grok Build

Start an interactive session with the Orq-routed model:
grok -m orq-claude
For a headless one-shot completion:
grok -p "<prompt>" -m orq-claude --output-format plain --sandbox off

Configuration Reference

config.toml fields

FieldDescription
[models].defaultKey of the model block to use when -m is not passed
modelAI Gateway model identifier (e.g. anthropic/claude-sonnet-4-6, openai/gpt-4o)
base_urlSet to https://api.orq.ai/v3/router for all AI Gateway models
env_keyName of the environment variable that holds the API key
nameDisplay name shown in the Grok Build UI
context_windowContext window size in tokens
max_completion_tokensMaximum tokens in the completion

Adding more catalog models

Add one [model.<key>] block per model and use -m <key> to select at runtime:
[model.orq-gpt4o]
model = "openai/gpt-4o"
base_url = "https://api.orq.ai/v3/router"
env_key = "ORQ_API_KEY"
name = "GPT-4o via Orq"
context_window = 128000
max_completion_tokens = 16384

Troubleshooting

If the npm package @vibe-kit/grok-cli is installed, the bare grok command may resolve to it instead of the xAI binary. Use the absolute path ~/.grok/bin/grok or remove the npm package to restore the correct resolution.
Confirm the environment variable named in env_key is exported in the current shell and contains a valid Orq.ai API key. Run echo $ORQ_API_KEY to verify.
Confirm base_url is set to https://api.orq.ai/v3/router and env_key points to a valid Orq.ai API key (not an xAI or OpenAI key). Requests to the wrong endpoint will not appear in Orq.ai traces.
Verify the model field uses the exact AI Gateway identifier (e.g. anthropic/claude-sonnet-4-6). Check the available models in Workspace Settings → Models.