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
LTSrelease - Linux: use the distro-specific method listed on that page
On macOS with Homebrew:
brew install nodeVerify your environment:
node -v
npm -vInstall
npm install -g @vibe-kit/grok-cliVerify the install:
grok --versionConfigure
Grok CLI offers three ways to set a custom API endpoint. Priority: CLI flag > environment variable > config file. Pick whichever you prefer.
Option 1: Environment variables (recommended)
| Variable | Description |
|---|---|
GROK_BASE_URL | API root URL, replaces the default xAI endpoint (default https://api.x.ai/v1) |
GROK_API_KEY | Your 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:
grok --base-url <ApiBaseUrl />Launch
grokVerify
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).