# Gemini CLI

> Connect Google's official Gemini CLI (@google/gemini-cli) to LMU AI's third-party Gemini API via GOOGLE_GEMINI_BASE_URL and GEMINI_API_KEY on macOS, Linux, Windows, or CC Switch.

URL: https://docs.lmuai.ai/docs/tools/gemini-cli







**Gemini CLI** (`@google/gemini-cli`) is Google's open-source terminal coding agent with file editing, shell execution, search, MCP tools, and non-interactive scripting.

By setting `GOOGLE_GEMINI_BASE_URL` and `GEMINI_API_KEY`, you can route Gemini CLI directly to LMU AI's native Gemini `v1beta` endpoint without signing in to a Google account.

***

## Prerequisites [#prerequisites]

Before you start, make sure you have:

1. **Node.js 20 or later** (check with `node -v`)
2. An LMU AI `sk-` API key whose group supports Gemini models (see [Getting Started](../guide/getting-started))
3. Confirmed target Gemini model IDs on the console **Available Models** page, such as `gemini-3.1-pro-preview` or `gemini-3.8-flash` (full list in [Models](../guide/models))

***

## Step 1: Install Gemini CLI [#step-1-install-gemini-cli]

Pick the install method that fits your system:

<Tabs items="['NPM (cross-platform, recommended)', 'Homebrew (macOS / Linux)', 'Run without installing']">
  <Tab value="NPM (cross-platform, recommended)">
    ```bash
    npm install -g @google/gemini-cli
    ```

    Verify the installation:

    ```bash
    gemini --version
    ```
  </Tab>

  <Tab value="Homebrew (macOS / Linux)">
    ```bash
    brew install gemini-cli
    gemini --version
    ```
  </Tab>

  <Tab value="Run without installing">
    To try it out without a global install:

    ```bash
    npx @google/gemini-cli --version
    ```
  </Tab>
</Tabs>

***

## Step 2: Configure the third-party Gemini API [#step-2-configure-the-third-party-gemini-api]

Choose any of the three methods below. &#x2A;*Method 1 (one-click "Import to CCS" from the LMU AI console)** is the fastest and requires no manual file editing; on headless servers or CI environments, use Method 2 or Method 3.

### Method 1: One-click "Import to CCS" from the LMU AI console (easiest, recommended) [#method-1-one-click-import-to-ccs-from-the-lmu-ai-console-easiest-recommended]

If you use the [CC Switch](./cc-switch) desktop app, you can import your key directly from the console and activate it with one click:

1. Install and launch [CC Switch](./cc-switch) at least once (keep it running so its custom URL protocol is registered)
2. Sign in to the LMU AI console, open **API Keys**, locate a Gemini-enabled key (such as a `Gemini-官方API` group key or a universal key), and click **Import to CCS** (`导入到 CCS`) in the Actions column:

<img alt="Click &#x22;Import to CCS&#x22; next to your Gemini key in the LMU AI console" src="__img0" />

3. When your browser asks to open CC Switch, click **Allow / Open** — CC Switch imports your API key and LMU AI endpoint (`https://api.lmuai.ai`) automatically
4. Open CC Switch, select the **Gemini CLI** icon in the left sidebar, and click the activate button on **LMU AI · 灵眸** until its status shows &#x2A;*Active (`使用中`)** (CC Switch writes `~/.gemini/.env` and `~/.gemini/settings.json` for you):

<img alt="Activate LMU AI under the Gemini CLI tab in CC Switch" src="__img1" />

5. If Gemini CLI is already open in a terminal, **restart the session** for the new config to take effect

<Callout type="info" title="Prefer adding it manually in CC Switch?">
  If your browser blocks protocol redirects or you want to manage multiple groups manually, click **+ Add Provider** in the top-right corner of CC Switch's Gemini CLI tab and fill in Base URL `https://api.lmuai.ai`, your `sk-` key, and model ID. For redirect troubleshooting, see [CC Switch common issues](./cc-switch#common-issues).
</Callout>

### Method 2: Write `~/.gemini/.env` and `settings.json` manually (persistent config files) [#method-2-write-geminienv-and-settingsjson-manually-persistent-config-files]

Gemini CLI automatically loads environment variables from `~/.gemini/.env` (`%USERPROFILE%\.gemini\.env` on Windows) along with auth and model preferences from `~/.gemini/settings.json`.

<Tabs items="['macOS / Linux', 'Windows (PowerShell)']">
  <Tab value="macOS / Linux">
    ```bash
    mkdir -p ~/.gemini

    cat > ~/.gemini/.env << 'EOF'
    GOOGLE_GEMINI_BASE_URL=https://api.lmuai.ai
    GEMINI_API_KEY=sk-replace-with-your-lmuai-key
    GEMINI_MODEL=gemini-3.1-pro-preview
    EOF

    cat > ~/.gemini/settings.json << 'EOF'
    {
      "security": {
        "auth": {
          "selectedType": "gemini-api-key"
        }
      },
      "model": {
        "name": "gemini-3.1-pro-preview"
      }
    }
    EOF
    ```
  </Tab>

  <Tab value="Windows (PowerShell)">
    ```powershell
    New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.gemini" | Out-Null

    @"
    GOOGLE_GEMINI_BASE_URL=https://api.lmuai.ai
    GEMINI_API_KEY=sk-replace-with-your-lmuai-key
    GEMINI_MODEL=gemini-3.1-pro-preview
    "@ | Set-Content -Path "$env:USERPROFILE\.gemini\.env" -Encoding utf8

    @"
    {
      "security": {
        "auth": {
          "selectedType": "gemini-api-key"
        }
      },
      "model": {
        "name": "gemini-3.1-pro-preview"
      }
    }
    "@ | Set-Content -Path "$env:USERPROFILE\.gemini\settings.json" -Encoding utf8
    ```
  </Tab>
</Tabs>

<Callout type="warn" title="Do not append /v1beta or /v1 to Base URL">
  Set `GOOGLE_GEMINI_BASE_URL` to the bare host `https://api.lmuai.ai`:

  * ✅ `https://api.lmuai.ai` (the CLI appends `/v1beta/models/...` automatically)
  * ❌ `https://api.lmuai.ai/v1beta` (results in `/v1beta/v1beta/...` and HTTP 404)
  * ❌ `https://api.lmuai.ai/v1` (OpenAI-compatible path; Gemini CLI speaks the native Gemini protocol)
</Callout>

### Method 3: Shell environment variables (for CI/CD or temporary sessions) [#method-3-shell-environment-variables-for-cicd-or-temporary-sessions]

To configure only the current shell session or an automated pipeline:

<Tabs items="['macOS / Linux (zsh / bash)', 'Windows (PowerShell)']">
  <Tab value="macOS / Linux (zsh / bash)">
    ```bash
    export GOOGLE_GEMINI_BASE_URL="https://api.lmuai.ai"
    export GEMINI_API_KEY="sk-replace-with-your-lmuai-key"
    export GEMINI_MODEL="gemini-3.1-pro-preview"
    ```

    To make them persistent, append those three lines to `~/.zshrc` or `~/.bashrc` and run `source ~/.zshrc`.
  </Tab>

  <Tab value="Windows (PowerShell)">
    ```powershell
    $env:GOOGLE_GEMINI_BASE_URL = "https://api.lmuai.ai"
    $env:GEMINI_API_KEY = "sk-replace-with-your-lmuai-key"
    $env:GEMINI_MODEL = "gemini-3.1-pro-preview"
    ```
  </Tab>
</Tabs>

<Callout type="info" title="Precedence note">
  Shell environment variables take precedence over `~/.gemini/.env`. If editing `.env` has no effect, check whether your shell already exports an older value.
</Callout>

***

## Step 3: Verify and switch models [#step-3-verify-and-switch-models]

### Non-interactive connectivity check [#non-interactive-connectivity-check]

Run a single prompt from the terminal to confirm everything works:

```bash
gemini -p "Reply in one short sentence confirming you are working."
```

Once you get a response, run `gemini` inside your project folder to start an interactive coding session.

### Choosing and switching models [#choosing-and-switching-models]

Available Gemini text and multimodal models on LMU AI:

| Model ID                                | Tier     | Best for                                                         |
| --------------------------------------- | -------- | ---------------------------------------------------------------- |
| `gemini-3.1-pro-preview`                | Flagship | Complex codebases, multi-file refactoring, long-context analysis |
| `gemini-3.8-flash`                      | Fast     | Daily coding, quick Q\&A, high-frequency agent loops             |
| `gemini-3.7-flash` / `gemini-3.6-flash` | Fast     | General development and chat                                     |
| `gemini-3.5-flash-lite`                 | Lite     | Batch lightweight tasks and scripted automation                  |

Model selection precedence (highest to lowest):

1. **CLI flag**: `gemini -m gemini-3.8-flash`
2. **Environment variable**: `GEMINI_MODEL=gemini-3.8-flash`
3. **Config file default**: `model.name` in `~/.gemini/settings.json`
4. **Interactive command**: run `/model` inside an active CLI session

***

## Troubleshooting [#troubleshooting]

### 1. Still prompted for Google account login (OAuth) [#1-still-prompted-for-google-account-login-oauth]

* Verify `~/.gemini/settings.json` contains `"security": { "auth": { "selectedType": "gemini-api-key" } }`
* Verify `GEMINI_API_KEY` is present in `~/.gemini/.env` or your current shell environment
* If you previously logged in via OAuth, run `/auth` inside Gemini CLI and select **Use Gemini API Key**

### 2. `404 Not Found` [#2-404-not-found]

* Check that `GOOGLE_GEMINI_BASE_URL` does **not** end with `/v1beta` or `/v1` — it must be `https://api.lmuai.ai`
* Confirm the model ID in `GEMINI_MODEL` or `-m` is spelled accurately and enabled for your API key's group

### 3. `401 Unauthorized` or traffic still hits Google's official host [#3-401-unauthorized-or-traffic-still-hits-googles-official-host]

Check for conflicting variables in your shell:

```bash
env | grep -E 'GOOGLE_|GEMINI_'
```

If `GOOGLE_API_KEY` or `GOOGLE_GENAI_USE_VERTEXAI=true` is set, run `unset GOOGLE_API_KEY GOOGLE_GENAI_USE_VERTEXAI`, remove them from `~/.zshrc` / `~/.bashrc`, and open a new terminal.

### 4. Model unavailable / `No available accounts` [#4-model-unavailable--no-available-accounts]

Your key's group does not include the requested Gemini model. Check **Available Models** in the console or switch to a group key / universal key that includes Gemini. See [Error Codes](../guide/errors) for more details.

***

## Next steps [#next-steps]

* Want to use the third-party Gemini API in **Antigravity, OpenCode, Cline / Roo Code / Kilo Code, Cherry Studio**, or **Python / TypeScript SDKs**? Read the [Third-Party Gemini API in Agent Tools & SDKs](./gemini-third-party-tools) guide
* Need live web search with structured citations? See the [Gemini Web Search API](/docs/api/gemini-search)
* Need Gemini text-to-image or image editing? See the [Gemini Image API](/docs/api/gemini-image)
