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:
- Node.js 20 or later (check with
node -v) - An LMU AI
sk-API key whose group supports Gemini models (see Getting Started) - Confirmed target Gemini model IDs on the console Available Models page, such as
gemini-3.1-pro-previeworgemini-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-cliVerify the installation:
gemini --versionbrew install gemini-cli
gemini --versionTo try it out without a global install:
npx @google/gemini-cli --versionStep 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.
Method 1: One-click "Import to CCS" from the LMU AI console (easiest, recommended)
If you use the CC Switch desktop app, you can import your key directly from the console and activate it with one click:
- Install and launch CC Switch at least once (keep it running so its custom URL protocol is registered)
- Sign in to the LMU AI console, open API Keys, locate a Gemini-enabled key (such as a
Gemini-官方APIgroup key or a universal key), and click Import to CCS (导入到 CCS) in the Actions column:

- 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 - 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/.envand~/.gemini/settings.jsonfor you):

- 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"
}
}
EOFNew-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 utf8Do 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 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):
- CLI flag:
gemini -m gemini-3.8-flash - Environment variable:
GEMINI_MODEL=gemini-3.8-flash - Config file default:
model.namein~/.gemini/settings.json - Interactive command: run
/modelinside an active CLI session
Troubleshooting
1. Still prompted for Google account login (OAuth)
- Verify
~/.gemini/settings.jsoncontains"security": { "auth": { "selectedType": "gemini-api-key" } } - Verify
GEMINI_API_KEYis present in~/.gemini/.envor your current shell environment - If you previously logged in via OAuth, run
/authinside Gemini CLI and select Use Gemini API Key
2. 404 Not Found
- Check that
GOOGLE_GEMINI_BASE_URLdoes not end with/v1betaor/v1— it must behttps://api.lmuai.ai - Confirm the model ID in
GEMINI_MODELor-mis 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
- 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 guide
- Need live web search with structured citations? See the Gemini Web Search API
- Need Gemini text-to-image or image editing? See the Gemini Image API
Last updated:
Still have questions? Ask in the LMU AI Community (in Chinese) and sign in with your console account.
Get an LMU AI key and start using Claude, Codex and more
Free sign-up, flexible plans, one key across Claude Code, Codex CLI, Cursor, VS Code, OpenCode, Cherry Studio and other AI tools.
Sign up