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

# Grok CLI

> 在 Grok CLI 中使用 S2 模型进行 AI 编程

## 安装 Grok CLI

如果你的设备尚未安装 Node.js，请先安装 Node.js 18 及以上版本，再执行以下命令安装 Grok CLI。

你可以访问官网安装，也可以通过命令安装：

<CodeGroup>
  ```bash macOS (Homebrew) theme={null}
  brew install node
  ```

  ```bash Ubuntu / Debian theme={null}
  sudo apt update && sudo apt install -y nodejs npm
  ```

  ```powershell Windows (winget) theme={null}
  winget install OpenJS.NodeJS.LTS
  ```
</CodeGroup>

如果你更习惯图形界面安装，也可以访问：

<CodeGroup>
  ```bash macOS / Linux - 安装 Node.js theme={null}
  https://nodejs.org/
  ```

  ```powershell Windows - 安装 Node.js theme={null}
  https://nodejs.org/
  ```
</CodeGroup>

安装完成后，执行以下命令安装 Grok CLI：

<CodeGroup>
  ```bash macOS / Linux theme={null}
  npm install -g @vibe-kit/grok-cli
  ```

  ```powershell Windows theme={null}
  npm install -g @vibe-kit/grok-cli
  ```
</CodeGroup>

<Note>
  更多安装细节与进阶用法请参考 [ xAI 官方文档](https://grokcli.io/)。
</Note>

## 配置 SenseAudio API

<Info>
  **还没有 API Key？** 请先订阅 [Token Plan](https://senseaudio.cn/tokenplan)，然后在控制台 **账户管理 → Token Plan** 创建专属 API Key。套餐额度用尽或达到限制后，可开启 **Extra Usage**，超出部分将自动按量计费、从账户余额扣费。
</Info>

<Steps>
  <Step title="设置环境变量">
    你可以先在当前终端中临时设置环境变量；如果希望长期生效，请写入对应系统的环境变量配置。

    <CodeGroup>
      ```bash macOS / Linux（临时生效） theme={null}
      export GROK_BASE_URL="https://api.senseaudio.cn/v1"
      export GROK_API_KEY="<SENSEAUDIO_API_KEY>"
      ```

      ```powershell Windows（PowerShell 临时生效） theme={null}
      $env:GROK_BASE_URL="https://api.senseaudio.cn/v1"
      $env:GROK_API_KEY="<SENSEAUDIO_API_KEY>"
      ```
    </CodeGroup>

    macOS / Linux 如需长期生效，可以将环境变量写入 Shell 配置文件：

    <CodeGroup>
      ```bash zsh theme={null}
      nano ~/.zshrc
      ```

      ```bash bash theme={null}
      nano ~/.bashrc
      ```
    </CodeGroup>

    在文件末尾加入以下内容，保存后重新打开终端，或执行 `source ~/.zshrc` / `source ~/.bashrc` 生效：

    ```bash theme={null}
    export GROK_BASE_URL="https://api.senseaudio.cn/v1"
    export GROK_API_KEY="<SENSEAUDIO_API_KEY>"
    ```

    如果需要在 Windows 桌面环境中长期生效，请按以下步骤配置：

    1. 打开 **开始菜单**，搜索 **环境变量**。
    2. 点击 **编辑系统环境变量**。
    3. 在弹出的窗口中点击 **环境变量**。
    4. 在 **用户变量** 中点击 **新建**，分别添加：
       * 变量名：`GROK_BASE_URL`，变量值：`https://api.senseaudio.cn/v1`
       * 变量名：`GROK_API_KEY`，变量值：你的 SenseAudio Token Plan API Key
    5. 保存后重新打开终端，再启动 Grok CLI。
  </Step>

  <Step title="启动 Grok CLI">
    <CodeGroup>
      ```bash macOS / Linux theme={null}
      grok --model senseaudio-s2
      ```

      ```powershell Windows theme={null}
      grok --model senseaudio-s2
      ```
    </CodeGroup>
  </Step>
</Steps>

运行效果如下：

<img src="https://mintcdn.com/sa-5efeb1e4/2uwj4t1TiXTu6X9i/images/token-plan/20260422204810.jpg?fit=max&auto=format&n=2uwj4t1TiXTu6X9i&q=85&s=6ced048ee8f849f8b5d80171ca7bb2ec" width="100%" data-path="images/token-plan/20260422204810.jpg" />

<Tip>
  macOS / Linux 中通过 `export` 设置的变量只在当前终端会话内生效；如果希望长期生效，建议写入 `~/.zshrc` 或 `~/.bashrc`。Windows 中通过 PowerShell 设置的 `$env:` 变量也只在当前终端会话内生效。
</Tip>

## 相关资源

<CardGroup cols={2}>
  <Card title="Codex CLI" icon="terminal" href="/guides/token-plan/codex-cli" />

  <Card title="Claude Code" icon="sparkles" href="/guides/token-plan/claude-code" />

  <Card title="S2 使用技巧" icon="lightbulb" href="/guides/token-plan/best-practices" />

  <Card title="常见问题" icon="circle-question" href="/guides/token-plan/faq">
    订阅、限额、切换、开票等问题解答。
  </Card>
</CardGroup>
