Skip to main content
“Grok CLI” can now refer to two different tools:
  • Grok Build, xAI’s official coding agent;
  • Community Grok CLI, an open-source project that is not affiliated with xAI.
Both official Grok Build and Community Grok CLI have been verified to call models through BetterToken. Each client returned a model response with a BetterToken API Key, Base URL, and Model ID. This guide presents Community Grok CLI first because its configuration is more direct.
Both tools use the grok command. If both are installed, your terminal runs whichever executable appears first in PATH, which can make the configuration seem ineffective. Keep one version or install them in separate environments.

What is the difference between Grok CLI and Grok Build?

This guide only covers text and code model requests through BetterToken. It does not cover xAI-specific APIs such as X Search, speech transcription, image generation, or video generation.

Use Community Grok CLI with BetterToken

The following commands apply to macOS, Linux, and WSL. Native Windows installation and configuration have not been verified for the community client.

Install

If Bun is already installed, you can use:
The old @vibe-kit/grok-cli package is no longer the installation path recommended by the project’s current README.

Configure BetterToken

Replace YOUR_MODEL_ID with the complete Model ID from the model plaza. Use your own BetterToken API Key: register and get one.

Verify the connection

Only a model response confirms that the API Key, Base URL, and Model ID are effective. Starting the client alone does not verify the model request.
Community Grok CLI has been verified to return a model response through BetterToken. This result only covers the basic text and code model requests configured on this page, not tool calls or xAI-specific features.
An open Grok CLI session does not automatically reload environment variables. Exit and restart it after changing the configuration.

Switch models

Change GROK_MODEL to another complete Model ID, restart Grok CLI, and repeat the short request.

Official Grok Build

Grok Build is xAI’s official terminal coding agent. It supports an interactive TUI, headless operation, and ACP.

Install

Use an xAI account or API key

Grok Build opens a browser for authentication on first launch. xAI documents XAI_API_KEY for environments without a browser:

Optional: configure BetterToken in Grok Build

Grok Build supports OpenAI-compatible custom models with a Base URL, Model ID, authentication environment variable, and request protocol.
BETTERTOKEN_API_KEY is an example variable name, not a fixed Grok Build requirement. Grok Build reads whichever environment variable env_key names.
Grok Build has been verified to return a model response with a BetterToken API Key, Base URL, and Model ID. This result only covers the text and code model requests described here; it does not verify tool calls or xAI-specific APIs.

Avoid a grok command conflict

type -a grok and Get-Command grok -All list multiple commands with the same name. Remove the unused client or adjust PATH if both are installed.

Common errors

Available models and feature limits

Copy a complete Model ID that supports OpenAI-compatible calls from the model plaza. A configurable Base URL alone does not prove that a model family’s requests, tool calls, or context format are compatible.
This page only covers text and code model requests. BetterToken does not provide X Search, speech transcription, image generation, video generation, or other xAI-specific APIs through this setup.