Skip to content

Grok CLI

Grok CLI uses the OpenAI-compatible interface, so this service can be used directly as its custom API endpoint.

Prerequisites

Grok CLI is installed via npm, so you need:

  • Node.js 18+
  • npm (usually installed with Node.js)

Install Node.js from the official page: https://nodejs.org/en/download

  • macOS / Windows: download and install the LTS release
  • Linux: use the distro-specific method listed on that page

On macOS with Homebrew:

bash
brew install node

Verify your environment:

bash
node -v
npm -v

Install

bash
npm install -g @vibe-kit/grok-cli

Verify the install:

bash
grok --version

Configure

Grok CLI offers three ways to set a custom API endpoint. Priority: CLI flag > environment variable > config file. Pick whichever you prefer.

VariableDescription
GROK_BASE_URLAPI root URL, replaces the default xAI endpoint (default https://api.x.ai/v1)
GROK_API_KEYYour API key

Configuration example:

export GROK_BASE_URL="https://codex.openai.com/v1"
export GROK_API_KEY="codex_your_api_key"

For a quick test in the current shell, export the variables above and run grok.

To make this permanent, add the export statements to your shell profile (~/.zshrc or ~/.bashrc), then reload it with source ~/.zshrc.

Option 2: Config file

Edit the user settings file ~/.grok/user-settings.json:

{
  "apiKey": "codex_your_api_key",
  "baseURL": "https://codex.openai.com/v1",
  "defaultModel": "grok-code-fast-1"
}

Set baseURL to the service https://codex.openai.com/v1 address (with /v1). Replace defaultModel with any model the service supports.

Option 3: CLI flag

Override the endpoint at launch with --base-url:

bash
grok --base-url <ApiBaseUrl />

Launch

bash
grok

Verify

Start a conversation in Grok CLI. If you receive a normal response, the setup is working.

If you see an auth error, check that GROK_API_KEY is correct and that GROK_BASE_URL / baseURL points to the right service address (with /v1).

OpenAI-compatible gateway integration docs