Skip to content

Use Gemini CLI with the Gateway

Gemini CLI is Google's open-source terminal AI agent. You can override its base URL to route requests through the Gateway, giving you regional data residency and budget controls.

Prerequisites

  • Gemini CLI installed (npm install -g @google/gemini-cli)
  • An LLM API key

Connect Gemini CLI to the Gateway

Gemini CLI speaks Google's Gemini API format. The Gateway accepts that format, so you only need to change the base URL. Use Gemini models (for example gemini-2.5-flash or gemini-2.5-pro). Claude models don't work through Gemini CLI today.

Step 1 — Set your key and endpoint

Add to your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish):

export GEMINI_API_KEY="your-api-key-here"
export GOOGLE_GEMINI_BASE_URL="https://llm.[your-region].amazee.ai"
export GEMINI_MODEL="gemini-2.5-flash"

Replace [your-region] with your region code (e.g. ch103, us103). No /v1 on the base URL.

Then reload your shell:

source ~/.zshrc   # or ~/.bashrc

Without the base URL, prompts go to Google

If GOOGLE_GEMINI_BASE_URL isn't set in the shell you start Gemini CLI from, your key and prompts go to Google's API, not the Gateway.

Unset other Google settings

If GOOGLE_API_KEY is set in your shell, Gemini CLI uses it instead of GEMINI_API_KEY. Run unset GOOGLE_API_KEY GOOGLE_GENAI_USE_VERTEXAI (and remove them from your shell profile) before you start Gemini CLI, so only your Gateway key is used.

Step 2 — Choose API-key sign-in

Create or edit ~/.gemini/settings.json:

{
  "security": { "auth": { "selectedType": "gemini-api-key" } },
  "model": { "name": "gemini-2.5-flash" }
}

Without the security block, Gemini CLI either asks you to sign in with Google (interactive) or fails with Invalid auth method selected (scripts).

You must set a model

Gemini CLI's own default model isn't on the Gateway. Set GEMINI_MODEL or model.name to a Gemini model from Available Models, or every request fails with 403 team not allowed to access model.

Step 3 — Check it works

gemini --skip-trust -p "Reply with the word pong"

You should get pong. --skip-trust is only needed for one-off headless runs. In interactive mode, Gemini CLI asks you to trust the folder.

Start Gemini CLI

cd /path/to/your/project
gemini

Switching models

gemini --model gemini-2.5-pro

Or change GEMINI_MODEL / model.name. Use Gemini model IDs exactly as /v1/models lists them.

Troubleshooting

"Invalid auth method selected"
Add "security": { "auth": { "selectedType": "gemini-api-key" } } to ~/.gemini/settings.json.
"not running in a trusted directory"
Headless runs need --skip-trust or GEMINI_CLI_TRUST_WORKSPACE=true. Or trust the folder once in interactive mode.
"An unexpected critical error occurred:[object Object]"
The real error is on the line above it. It's usually a 403 about the model name.
"403 team not allowed to access model"
The model named after "Tried to access" isn't on your key. If it's a name you didn't set (like gemini-3.8-flash), Gemini CLI fell back to its own default. Set GEMINI_MODEL.
"temperature and top_p cannot both be specified"
You picked a Claude model. Gemini CLI can't use Claude through the Gateway yet. Switch to a Gemini model.
"Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY." or "LiteLLM Virtual Key expected"
Unset GOOGLE_API_KEY. Gemini CLI prefers it over GEMINI_API_KEY.
Requests going to Google instead of the Gateway
Make sure GOOGLE_GEMINI_BASE_URL is set in the shell you start Gemini CLI from.