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

# Gemini CLI setup with LaoZhang API

> Point Gemini CLI at LaoZhang API with GEMINI_API_KEY and GOOGLE_GEMINI_BASE_URL, then code with Gemini 3.8 Flash and other models.

Gemini CLI connects to LaoZhang API through two environment variables, one for your key and one for the base URL, with the Gemini API key sign-in method. Requests use the native Gemini protocol and are billed by token.

| Item | Details |
| - | - |
| Key variable | `GEMINI_API_KEY` |
| Base URL variable | `GOOGLE_GEMINI_BASE_URL=https://api.laozhang.ai` |
| Sign-in method | Use Gemini API Key (`gemini-api-key`) |
| Recommended models | `gemini-3.8-flash`; `gemini-3.1-pro-preview` for complex work |
| Last verified | October 5, 2026, Gemini CLI 0.62.0 |

## Install Gemini CLI

Install it globally with npm (Node.js required):

```bash theme={null}
npm install -g @google/gemini-cli
gemini --version
```

## Configure LaoZhang API

<Steps>
  <Step title="Set the environment variables">
    Add these two lines to your shell profile (`~/.zshrc` for zsh, `~/.bashrc` for bash), then open a new terminal:

    ```bash theme={null}
    export GEMINI_API_KEY="YOUR_LAOZHANG_API_KEY"
    export GOOGLE_GEMINI_BASE_URL="https://api.laozhang.ai"
    ```

    Use the bare host, without `/v1` or `/v1beta`; Gemini CLI builds the path itself.
  </Step>

  <Step title="Choose Gemini API key sign-in">
    The first time you run `gemini`, it asks how to sign in. Choose **Use Gemini API Key**. You can also set it in `~/.gemini/settings.json`:

    ```json theme={null}
    {
      "security": {
        "auth": {
          "selectedType": "gemini-api-key"
        }
      }
    }
    ```

    Don't choose Login with Google, which connects to your Google account and bypasses LaoZhang API.
  </Step>

  <Step title="Pick a model and test">
    In a project directory, run:

    ```bash theme={null}
    gemini -m gemini-3.8-flash
    ```

    For a quick non-interactive check:

    ```bash theme={null}
    gemini -m gemini-3.8-flash -p "Reply with exactly one word: connected"
    ```

    Non-interactive mode only runs in a trusted directory. The first time you use a new directory, trust it from interactive mode.
  </Step>
</Steps>

## Choose a model

| Model | Use it for |
| - | - |
| `gemini-3.8-flash` | Everyday coding; fast and low-cost |
| `gemini-3.6-flash` | Comparing with 3.8 Flash or keeping an existing workflow |
| `gemini-3.1-pro-preview` | Complex reasoning and large codebases |

Pass `-m` every time you start, so Gemini CLI doesn't fall back to a default model ID that LaoZhang API doesn't offer. Prices are in the [model catalog](/en/models); routing details are in [Gemini protocol](/en/api-reference/gemini).

## FAQ

### I get "API key not valid" or requests go to Google

Make sure `GOOGLE_GEMINI_BASE_URL` is set in the current terminal (`echo $GOOGLE_GEMINI_BASE_URL`) and that the sign-in method is Gemini API key. A different `GEMINI_API_KEY` in your project directory or `~/.gemini/.env` may also be read, so check those too.

### The model doesn't exist

Model IDs must match the [model catalog](/en/models) exactly. Send `GET https://api.laozhang.ai/v1/models` with the same key to confirm the ID is listed.

### Can Gemini CLI generate images?

Gemini CLI is built for chat and coding. To generate images, call the Nano Banana API directly; see [Nano Banana API](/en/api-capabilities/nano-banana-image).

## Related pages

* [Integrations overview](/en/scenarios)
* [Gemini protocol: generateContent and SDK](/en/api-reference/gemini)
* [Gemini CLI on GitHub](https://github.com/google-gemini/gemini-cli)


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