Two environment variables point Google’s official Gemini CLI at apimodels and run the gemini-3 family on your balance — file edits, shell commands and multi-turn agent tasks all execute on your own machine. About 2 minutes.
| Variable | Value |
|---|---|
| GOOGLE_GEMINI_BASE_URL | https://api.apimodels.app |
| GEMINI_API_KEY | Your apimodels API Key (starts with sk_, paste as-is) |
| -m / --model | gemini-3-flash-preview (fast & cheap) or gemini-3.1-pro-preview (strongest) |
Important: set the base URL to https://api.apimodels.app — no /v1beta or any path; the SDK appends /v1beta/models/… itself. Both generateContent and streamGenerateContent (SSE streaming) are supported, so every call shape the CLI makes is covered.
npm install -g @google/gemini-cli
# 或临时试用 / or try it without installing:
npx @google/gemini-cliRequires Node.js 20+. Run gemini --version after install; a version number means success.
macOS / Linux
# ~/.zshrc
echo 'export GOOGLE_GEMINI_BASE_URL="https://api.apimodels.app"' >> ~/.zshrc
echo 'export GEMINI_API_KEY="sk_…your_apimodels_key…"' >> ~/.zshrc
source ~/.zshrcWindows (PowerShell)
# PowerShell
[Environment]::SetEnvironmentVariable("GOOGLE_GEMINI_BASE_URL", "https://api.apimodels.app", "User")
[Environment]::SetEnvironmentVariable("GEMINI_API_KEY", "sk_…your_apimodels_key…", "User")On first launch the CLI asks how to authenticate — pick “Use Gemini API key”, NOT Google account login (which bypasses the base URL and goes straight to Google).
curl -s "https://api.apimodels.app/v1beta/models/gemini-3-flash-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "contents": [{ "role": "user", "parts": [{ "text": "Reply with exactly: ok" }] }] }'A response containing "text": "ok" means you are through. This curl authenticates with the x-goog-api-key header — exactly what Gemini CLI sends — so if it works, the CLI works.
cd your-project
gemini -m gemini-3-flash-preview| Model id | Notes |
|---|---|
| gemini-3.1-pro-preview | Strongest — complex refactors, long tasks |
| gemini-3-pro-preview | Strong reasoning |
| gemini-3-flash-preview | Fast & cheap — the daily default |
| gemini-2.5-pro / gemini-2.5-flash | Previous generation, lower price |
Tool calling (the functionCall capability that file edits and shell commands depend on) is verified working on all of these.
| 401 / Invalid API key | GEMINI_API_KEY not loaded (reopen the terminal or source ~/.zshrc), or a wrong key. Verify with the curl above. |
| Requests go to Google instead of apimodels | You picked Google account login. Restart and choose “Use Gemini API key”; confirm GOOGLE_GEMINI_BASE_URL is exported. |
| 401 inside sandbox mode | The CLI sandbox may not inherit env vars (known upstream issue). Run without sandbox, or explicitly pass the two variables into the sandbox config. |
| Model-name errors | Use only the ids in the table above; the -thinking variants are for deep-reasoning API calls and are not needed in the CLI. |