APIMODELSAPIMODELS
Gemini CLI · gemini-3 family · terminal agent

Use apimodels in Gemini CLI

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.

Configuration values you need

VariableValue
GOOGLE_GEMINI_BASE_URLhttps://api.apimodels.app
GEMINI_API_KEYYour apimodels API Key (starts with sk_, paste as-is)
-m / --modelgemini-3.8-flash (fast) or gemini-4-argon (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.

Step 1 · Install Gemini CLI

npm install -g @google/gemini-cli
# 或临时试用 / or try it without installing:
npx @google/gemini-cli

Requires Node.js 20+. Run gemini --version after install; a version number means success.

Step 2 · Set the two environment variables

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 ~/.zshrc

Windows (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).

Step 3 · Sanity-check with curl, then launch

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

Available models

Model idNotes
gemini-4-argonStrongest — complex refactors, long tasks (1M context)
gemini-4-hydrogenFast — everyday coding and agent execution: write code, run tests, verify changes; the recommended upgrade from 3.8 Flash
gemini-4-carbonDeeper reasoning for hard multi-step debugging; uses more tokens per task, and Google still recommends Argon for most coding
gemini-3.1-pro-previewPrevious-generation Pro — complex tasks
gemini-3.8-flashFast — the daily default for coding and agents
gemini-3-flash-previewMost affordable — light tasks

Tool calling (the functionCall capability that file edits and shell commands depend on) is verified working on all of these.

Troubleshooting

401 / Invalid API keyGEMINI_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 apimodelsYou picked Google account login. Restart and choose “Use Gemini API key”; confirm GOOGLE_GEMINI_BASE_URL is exported.
401 inside sandbox modeThe 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 errorsUse only the ids in the table above; the -thinking variants are for deep-reasoning API calls and are not needed in the CLI.