> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nano-gpt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Grok CLI

> Use Grok CLI with NanoGPT and current Grok models

> [!NOTE]
>
> These examples use the direct API host, `https://api.nano-gpt.com`. It has no IPv6 address, so clients with only IPv6 should use `https://nano-gpt.com` with the same paths. See [API Hosts](https://docs.nano-gpt.com/api-reference/miscellaneous/api-hosts.md).

# Grok CLI

> Use Grok CLI with NanoGPT to access Grok and other available models through a single API key.

> [!TIP]
>
> [Get started with NanoGPT](https://nano-gpt.com/api) for pay-as-you-go pricing with no monthly fees.

NanoGPT provides an OpenAI-compatible endpoint that works with the Grok CLI. This lets you:

* Use Grok CLI with your NanoGPT credits
* Access Grok models without a separate xAI account
* Use any other NanoGPT model through the same CLI

## Step 1: Install Grok CLI

Prerequisites: [Node.js 18 or newer](https://nodejs.org/en/download/)

```bash theme={null}
# Install Grok CLI
npm install -g @vibe-kit/grok-cli

# Verify installation
grok --version
```

> [!NOTE]
>
> **Note**: If you encounter permission issues during installation, try using `sudo` (macOS/Linux) or running the command prompt as an administrator (Windows) to re-execute the installation command.

## Step 2: Configure NanoGPT

**1. Get API Key**

* Go to [NanoGPT API](https://nano-gpt.com/api)
* Create an account or log in
* Copy your API key

**2. Set Required Environment Variables**

Grok CLI reads these environment variables:

| Variable | Value | Description |
| - | - | - |
| `GROK_BASE_URL` | `https://api.nano-gpt.com/api/v1` | NanoGPT OpenAI-compatible endpoint |
| `GROK_API_KEY` | `sk-nano-YOUR-API-KEY` | Your NanoGPT API key |

> [tab] macOS & Linux
>
> ```bash theme={null}
> export GROK_BASE_URL="https://api.nano-gpt.com/api/v1"
> export GROK_API_KEY="sk-nano-YOUR-API-KEY"
> ```

> [tab] Windows PowerShell
>
> ```powershell theme={null}
> $env:GROK_BASE_URL = "https://api.nano-gpt.com/api/v1"
> $env:GROK_API_KEY = "sk-nano-YOUR-API-KEY"
> ```

> [tab] Windows Cmd
>
> ```cmd theme={null}
> set GROK_BASE_URL=https://api.nano-gpt.com/api/v1
> set GROK_API_KEY=sk-nano-YOUR-API-KEY
> ```

Replace `sk-nano-YOUR-API-KEY` with your actual API key. Open a new terminal for changes to take effect if you set persistent variables.

**3. Optional: Make It Persistent**

Add the variables to your shell profile (for example, `~/.zshrc` or `~/.bashrc`):

```bash theme={null}
echo 'export GROK_BASE_URL="https://api.nano-gpt.com/api/v1"' >> ~/.zshrc
echo 'export GROK_API_KEY="sk-nano-YOUR-API-KEY"' >> ~/.zshrc
source ~/.zshrc
```

## Step 3: Start Using Grok CLI

Launch Grok CLI with a specific model:

```bash theme={null}
grok --model x-ai/grok-latest
```

Since you are connected to NanoGPT, you can use any available model:

```bash theme={null}
# Grok models
grok --model x-ai/grok-latest
grok --model x-ai/grok-4.7

# Other providers through NanoGPT
grok --model openai/gpt-6.1-sol
grok --model anthropic/claude-opus-5.5
grok --model google/gemini-flash-latest
```

Model names are listed on our [pricing page](https://nano-gpt.com/pricing).

## Available Grok Models

| Model | Description |
| - | - |
| `x-ai/grok-latest` | Moving alias for the newest Grok model, currently Grok 4.7 |
| `x-ai/grok-4.7` | Grok 4.7; use this versioned ID to keep the model selection fixed |

Grok 4.7 is a paid model and is not included in the subscription. Check the
[live token, cache, and long-context pricing](https://api.nano-gpt.com/api/models/x-ai%2Fgrok-4.7/providers)
before starting a long session.

## Known Limitations

Grok 4.7 always uses reasoning. Grok CLI may show reasoning content in terminal output; hiding that content does not turn off reasoning or its token cost.

For other coding clients supported by NanoGPT, see [Claude Code](https://docs.nano-gpt.com/integrations/claude-code.md) or [Codex CLI](https://docs.nano-gpt.com/integrations/codex-cli.md).

## Troubleshooting

| Issue | Solution |
| - | - |
| `401 Unauthorized` | Check your API key is correct and has credits |
| `GROK_BASE_URL not set` | Ensure the environment variable is exported |
| `Model not found` | Verify the model name at [nano-gpt.com/pricing](https://nano-gpt.com/pricing) |
| `Command not found: grok` | Run `npm install -g @vibe-kit/grok-cli` again |
| Thinking content flooding output | Grok 4.7 always reasons; choose a different model with reasoning disabled if you need non-thinking generation |

## FAQ

### Is Grok CLI official xAI software?

No. Grok CLI is a third-party package. NanoGPT works with it by providing an OpenAI-compatible endpoint.

### Can I access Grok models from other clients?

Yes. You can use Grok models from Claude Code, Cursor, or any OpenAI-compatible client by setting the base URL to NanoGPT.

## API Details (Reference)

| Setting | Value |
| - | - |
| Base URL | `https://api.nano-gpt.com/api/v1` |
| Chat Completions Endpoint | `POST /chat/completions` |
| Models Endpoint | `GET /models` |
| Auth Header | `Authorization: Bearer sk-nano-...` |

### Example cURL (verify connection)

```bash theme={null}
curl -X POST "https://api.nano-gpt.com/api/v1/chat/completions" \
  -H "Authorization: Bearer sk-nano-YOUR-API-KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "x-ai/grok-latest",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.