# Grok CLI

Source: https://docs.aicentos.com/en/clients/grok-cli

Language: en

> Use aicentos in Grok CLI — connect through environment variables or a configuration file

Grok CLI is a command-line tool that uses the OpenAI-compatible interface, so a custom API address can be plugged in directly as its backend service.

## Prerequisites

You need Node.js 18+ and npm installed first.

The recommended source is the official Node.js download page: [https://nodejs.org/en/download](https://nodejs.org/en/download)

* macOS/Windows: download and install the LTS version
* Linux: install using the distro instructions

macOS users can also use Homebrew:

```bash
brew install node
```

After the installation, confirm:

```bash
node -v
npm -v
```

## Install Grok CLI

Install globally with npm:

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

After the installation, verify:

```bash
grok --version
```

## Configure the connection

Grok CLI offers three configuration methods with the following precedence: command-line arguments > environment variables > configuration file.

### Method 1: Environment variables (recommended)

Set the following environment variables:

```bash
export GROK_BASE_URL="https://aicentos.com/v1"
export GROK_API_KEY="your_api_key_here"
```

For a quick test, running the exports in the current shell is enough. To persist them, add the lines above to `~/.zshrc` or `~/.bashrc`, then run `source ~/.zshrc` to apply.

### Method 2: Configuration file

Edit `~/.grok/user-settings.json`:

```json
{
  "apiKey": "your_api_key_here",
  "baseURL": "https://aicentos.com/v1",
  "defaultModel": "gpt-4o"
}
```

### Method 3: Command-line arguments

Specify it through arguments at launch:

```bash
grok --base-url https://aicentos.com/v1
```

## Launch and use

Once configured, simply run:

```bash
grok
```

Start a conversation in Grok CLI; if replies come back normally, the integration is working.

## Verification and troubleshooting

If you hit authentication errors, check:

* Whether `GROK_API_KEY` is correct
* Whether `GROK_BASE_URL` / `baseURL` points to the correct service address (the `/v1` suffix is required)

After confirming the configuration is correct, just restart.

## Notes

* Grok CLI uses the OpenAI-compatible interface, so configuration is simple and direct
* The three configuration methods can be chosen freely; the environment variable method is recommended
* The API address must include the `/v1` suffix
* A custom default model is supported

## Related links

* Official documentation: [https://docs.aicentos.com/clients/grok-cli.html](https://docs.aicentos.com/clients/grok-cli.html)