Gemini CLI
Use Gemini CLI with a Lovely Router API key: set the base URL and key in two environment variables and pick a Gemini model.
Gemini CLI is Google's open-source AI agent for the terminal. It calls the Gemini API, which Lovely Router serves natively, so two environment variables point it at Lovely Router. You need an API key first.
Set up in one click#
On the API keys page, use Use in tools → Gemini CLI. The dialog shows the setup below with your key filled in, and Import with CC Switch adds Lovely Router as a provider in the CC Switch desktop app, with the models already set. CC Switch must be installed.
Right after you create a key, the dialog already contains it. For an existing key, paste the full key into the dialog: Lovely Router stores only a hash, so it can't show the key again.
Set the base URL and key#
Set the base URL and key, and pick a model:
export GOOGLE_GEMINI_BASE_URL=https://lovelyrouter.com
export GEMINI_API_KEY=$LOVELY_API_KEY
gemini -m gemini-3.1-proChoose a model#
-m picks the model. Any Gemini model id from GET /v1/models works, such as gemini-3.1-pro or gemini-3-flash. The model list has every id.
Add data tools over MCP#
The MCP server at https://lovelyrouter.com/mcp gives Gemini CLI the data tools and the browser agent, billed from the same balance. It authenticates with the same key:
gemini mcp add --transport http lovely https://lovelyrouter.com/mcp \
--header "Authorization: Bearer $LOVELY_API_KEY"This adds it to .gemini/settings.json in the current project. Add --scope user to use it in every project. Run gemini mcp list to check it. For the full list of tools, see MCP server.
Troubleshooting#
| Symptom | Fix |
|---|---|
401 with Missing API key | Gemini CLI isn't sending the key. Check that GEMINI_API_KEY is exported in the shell that starts gemini. |
401 with Invalid or revoked API key | The key is mistyped, truncated or revoked. Paste it again, or create a new one. |
404 with Model '...' is not available | The model id doesn't exist. Copy a Gemini model id from GET /v1/models or the model list. |
404 with Unknown endpoint /v1/v1beta/... | GOOGLE_GEMINI_BASE_URL ends in /v1, and Gemini CLI adds the version path itself. Set it to https://lovelyrouter.com. |
402 | Your balance is empty or the key reached its spend limit. See Credits & billing. |
Every other status is covered in Errors.