Gemini CLI
Configure Gemini CLI with RunAPI's Gemini native API, verify requests, and restore your previous setup.
Overview
Gemini CLI is a terminal agent. This guide changes its model provider to RunAPI’s Gemini native API; adding RunAPI tools through MCP is a separate step.
Before you begin
Follow the official installation guide. Create a dedicated standard API key using the Authentication Guide, then copy a Gemini-native model ID from the Model Catalog. Never commit your key.
npm install -g @google/gemini-cli
Configure RunAPI
Start with these variables in your current shell. The base URL is the HTTPS API root, without /v1beta; the SDK adds POST /v1beta/models/{model}:streamGenerateContent?alt=sse. HTTP is only allowed for localhost.
export GOOGLE_GEMINI_BASE_URL=https://runapi.ai
export GEMINI_API_KEY=YOUR_RUNAPI_API_KEY
export GEMINI_MODEL=YOUR_RUNAPI_MODEL_ID
For persistent use, put the same three variables in ~/.gemini/.env, outside your repositories. Restrict access with chmod 600 ~/.gemini/.env. Gemini CLI searches for .env from the current directory toward its parents, then checks ~/.gemini/.env and ~/.env; check for competing files.
Merge these two settings into ~/.gemini/settings.json, preserving unrelated settings. Use gemini-api-key for API-key authentication; do not reuse a cached Google login. The key is sent in x-goog-api-key by default.
{
"security": {
"auth": {"selectedType": "gemini-api-key"}
},
"model": {"name": "YOUR_RUNAPI_MODEL_ID"}
}
Choose a model
Use GEMINI_MODEL, --model YOUR_RUNAPI_MODEL_ID, or /model in an interactive session. Avoid auto, pro, and flash: these aliases can resolve to Google model IDs not available in RunAPI. Internal routing, classification, and loop detection can also request flash or flash-lite auxiliary models; check their availability separately.
Verify
Run this in a repository you trust. Check the model with /about or /stats in an interactive session, then confirm a matching streamGenerateContent request in RunAPI usage records. A successful CLI response alone does not prove which endpoint received it.
gemini --version
gemini -p "Describe this repository in one sentence."
Add RunAPI tools
MCP adds tools, not a model provider. This command registers the local server; follow Local MCP for its separate authentication and verification.
gemini mcp add runapi npx -y @runapi.ai/mcp
Troubleshoot
If requests still go to Google, check competing .env files, security.auth.selectedType, cached login, and Google/Vertex authentication environment settings. If you see Invalid auth method selected, select gemini-api-key in settings rather than gateway and restart.
A 401 means you should check the key and any GEMINI_API_KEY_AUTH_MECHANISM override; the default uses x-goog-api-key. For 404, remove /v1beta from the base URL and copy a supported Gemini-native model ID again. For an unavailable auxiliary model, check the exact requested ID; selecting a main model does not guarantee every CLI feature works.
RunAPI does not expose countTokens or embedContent. Gemini CLI can fall back to local token estimation when countTokens fails; estimates may differ from usage records. Use HTTPS except for localhost, and do not disable certificate verification.
Remove RunAPI
Remove the three variables from your shell and saved .env files, restore your previous security.auth.selectedType and model setting, and revoke the dedicated key in RunAPI. Remove the separately added MCP server only if you no longer need its tools.
unset GOOGLE_GEMINI_BASE_URL GEMINI_API_KEY GEMINI_MODEL
Next steps
Continue with LLM API Quickstart, Gemini generateContent, streamGenerateContent, the Model Catalog, or Local MCP.