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.

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

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

Step 1: Install Gemini CLI

Pick the install method that fits your system:

npm install -g @google/gemini-cli

Verify the installation:

gemini --version
brew install gemini-cli
gemini --version

To try it out without a global install:

npx @google/gemini-cli --version

Step 2: Configure the third-party Gemini API

Choose any of the three methods below. 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.

If you use the 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 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:

Click "Import to CCS" next to your Gemini key in the LMU AI console

  1. 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
  2. Open CC Switch, select the Gemini CLI icon in the left sidebar, and click the activate button on LMU AI · 灵眸 until its status shows Active (使用中) (CC Switch writes ~/.gemini/.env and ~/.gemini/settings.json for you):

Activate LMU AI under the Gemini CLI tab in CC Switch

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

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.

Method 2: Write ~/.gemini/.env and settings.json 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.

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

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)

Method 3: Shell environment variables (for CI/CD or temporary sessions)

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

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.

$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"

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.


Step 3: Verify and switch models

Non-interactive connectivity check

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

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

Available Gemini text and multimodal models on LMU AI:

Model IDTierBest for
gemini-3.1-pro-previewFlagshipComplex codebases, multi-file refactoring, long-context analysis
gemini-3.8-flashFastDaily coding, quick Q&A, high-frequency agent loops
gemini-3.7-flash / gemini-3.6-flashFastGeneral development and chat
gemini-3.5-flash-liteLiteBatch 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

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

  • 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

Check for conflicting variables in your shell:

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

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 for more details.


Next steps

Last updated:

Still have questions? Ask in the LMU AI Community (in Chinese) and sign in with your console account.

On this page