Grok CLI
Add GreenTokens models to xAI's Grok CLI.
Install
Grok CLI (Grok Build) is xAI's terminal coding agent. It needs Node 20 or newer for the npm install.
npm install -g @xai-official/grokQuick setup
Run the setup script in a terminal and choose Grok CLI from its list. It finds Grok CLI's settings, checks your API key, and makes the changes described below for you, backing up each file first. It can set up your other agents in the same run.
curl -fsSL https://www.greentokens.io/setup.sh | bashThe script saves your key as the GREENTOKENS_API_KEY environment variable, which Grok CLI reads. Open a new terminal window afterwards so it picks it up.
Add GreenTokens models
Grok CLI supports custom OpenAI-compatible endpoints in its config file. Add one block per GreenTokens model you want to use:
[models]
default = "grok-4.7"
[model."grok-4.7"]
model = "grok-4.7"
name = "Grok 4.7 (GreenTokens)"
base_url = "https://api.greentokens.io/v1"
env_key = "GREENTOKENS_API_KEY"
api_backend = "chat_completions"
[model."claude-sonnet-5"]
model = "claude-sonnet-5"
name = "Claude Sonnet 5 (GreenTokens)"
base_url = "https://api.greentokens.io/v1"
env_key = "GREENTOKENS_API_KEY"
api_backend = "chat_completions"modelis the GreenTokens model ID sent to the API. Any text model from the models page works, not just Grok.base_urlishttps://api.greentokens.io/v1: Grok CLI adds/chat/completionsitself.env_keynames the environment variable holding your key, so it never sits in the file.
[model."grok-4.7"], not [model.grok-4.7].Run it
export GREENTOKENS_API_KEY="sk-gt-…"
grok # uses the default model
grok -m claude-sonnet-5 # or pick oneSwitch models inside a session with /model or Ctrl+M.