> ## 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

<AccordionGroup>
  <Accordion title="Invalid API Key error">
    Verify `GEMINI_API_KEY` is set correctly. Run `echo $GEMINI_API_KEY` to check.
  </Accordion>

  <Accordion title="fetch failed">
    Network restrictions may block the connection. Try a system-wide proxy.
  </Accordion>

  <Accordion title="Wrong Node.js version">
    Gemini CLI requires Node.js 22+. Run `node --version` to check.
  </Accordion>

  <Accordion title="Uninstall Gemini CLI">
    Run `npm uninstall -g @google/gemini-cli`.
  </Accordion>
</AccordionGroup>

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/gemini-cli#howto",
        "name": "Use Gemini CLI with CometAPI",
        "description": "Use this guide to configure Gemini CLI with CometAPI credentials, base URL settings, and Gemini model IDs.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/gemini-cli#step-1",
            "position": 1,
            "name": "Install Gemini CLI",
            "text": "Complete the Install Gemini CLI step in the Use Gemini CLI with CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/gemini-cli#step-2",
            "position": 2,
            "name": "Set environment variables",
            "text": "Complete the Set environment variables step in the Use Gemini CLI with CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/gemini-cli#step-3",
            "position": 3,
            "name": "Start Gemini CLI",
            "text": "Complete the Start Gemini CLI step in the Use Gemini CLI with CometAPI guide."
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI Docs",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Integrations",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "Use Gemini CLI with CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/gemini-cli"
          }
        ]
      }
    ]
    }
    `}
</script>
