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

# Use Gemini CLI with CometAPI

> Use this guide to configure Gemini CLI with CometAPI credentials, base URL settings, and Gemini model IDs.

Use this guide to run [Gemini CLI](https://github.com/google-gemini/gemini-cli) with CometAPI as the API endpoint.

Official references:

* [Gemini CLI GitHub](https://github.com/google-gemini/gemini-cli)
* [Gemini CLI Authentication](https://github.com/google-gemini/gemini-cli/blob/main/docs/get-started/authentication.mdx)

<Note>
  Model availability changes over time. Check the [CometAPI Models page](/overview/models)
  for available Gemini models.
</Note>

## Prerequisites

| Requirement  | Details                                                                      |
| ------------ | ---------------------------------------------------------------------------- |
| Node.js      | 22+ (LTS recommended)                                                        |
| OS           | macOS, Linux, or Windows                                                     |
| CometAPI key | From your [CometAPI Dashboard](https://www.cometapi.com) (starts with `sk-`) |

## Setup

<Steps>
  <Step title="Install Gemini CLI">
    ```bash theme={null}
    npm install -g @google/gemini-cli
    ```

    Or via Homebrew (macOS / Linux):

    ```bash theme={null}
    brew install gemini-cli
    ```

    Verify:

    ```bash theme={null}
    gemini --version
    ```
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export GEMINI_API_KEY="sk-your-cometapi-key"
    export GOOGLE_GEMINI_BASE_URL="https://api.cometapi.com"
    ```

    Replace `sk-your-cometapi-key` with your actual CometAPI key.
  </Step>

  <Step title="Start Gemini CLI">
    ```bash theme={null}
    cd your-project
    gemini
    ```

    On first launch, you'll be prompted to choose a theme, confirm the safety notice, and trust the working directory.
  </Step>
</Steps>

## Persist environment variables

To avoid re-exporting every session, add to your shell config:

```bash theme={null}
# Add to ~/.zshrc (macOS) or ~/.bashrc (Linux)
export GEMINI_API_KEY="sk-your-cometapi-key"
export GOOGLE_GEMINI_BASE_URL="https://api.cometapi.com"
```

Restart your terminal for changes to take effect.

## Troubleshooting

| Symptom                 | Fix                                                                           |
| ----------------------- | ----------------------------------------------------------------------------- |
| `Invalid API Key` error | Verify `GEMINI_API_KEY` is set correctly. Run `echo $GEMINI_API_KEY` to check |
| `fetch failed`          | Network restrictions may block the connection. Try a system-wide proxy        |
| Wrong Node.js version   | Gemini CLI requires Node.js 22+. Run `node --version` to check                |
| Uninstall               | `npm uninstall -g @google/gemini-cli`                                         |
