Skip to content

Gemini CLI

Connect Google's Gemini CLI to CodaAPI. Set GOOGLE_GEMINI_BASE_URL and GEMINI_API_KEY, and choose API-key authentication in settings.json.

Gemini CLI is Google's command-line AI assistant. It calls models through the native Gemini API (/v1beta/models/…), which CodaAPI provides, so all you need to do is point its address and key at CodaAPI.

The configuration on this page has been tested on the CodaAPI gateway (Gemini CLI 0.64.0, November 2026). Settings may change when Gemini CLI updates, so its official documentation is authoritative.

Before you start:

  • Install Gemini CLI: npm install -g @google/gemini-cli.
  • A CodaAPI API key with Group set to Gemini-官转. To create one, see the Quickstart.
  • Pick a Gemini model, such as gemini-3-flash-preview (in the Gemini-官转 group). The models you can use are the ones marked with the Gemini endpoint type in Model Square that are also in your key's group.

Setup

1. Set the address and key

Gemini CLI reads the gateway address and key from two environment variables:

# macOS / Linux: add to ~/.zshrc or ~/.bashrc, then open a new terminal
export GOOGLE_GEMINI_BASE_URL="https://codaapi.com"
export GEMINI_API_KEY="sk-your-key"
# Windows: saves user environment variables; open a new terminal afterwards
setx GOOGLE_GEMINI_BASE_URL "https://codaapi.com"
setx GEMINI_API_KEY "sk-your-key"

Use the root address https://codaapi.com without /v1beta; Gemini CLI adds the API path itself.

2. Choose API-key authentication

By default Gemini CLI signs in with a Google account; switch it to an API key. Edit ~/.gemini/settings.json (on Windows, %USERPROFILE%\.gemini\settings.json), creating it if it doesn't exist:

{
  "security": {
    "auth": {
      "selectedType": "gemini-api-key"
    }
  }
}

If the file already has other settings, merge security.auth.selectedType into it. Without this setting, a non-interactive run fails with Invalid auth method selected; in an interactive session, the first start may ask how to sign in, so choose the Gemini API key option.

3. Run it

gemini -m gemini-3-flash-preview

To ask a single question without the interactive interface:

gemini -m gemini-3-flash-preview -p "Introduce yourself in one sentence"

When running non-interactively in a script or CI, Gemini CLI may ask you to trust the current folder first; set the environment variable GEMINI_CLI_TRUST_WORKSPACE=true to skip that step.

Import with CC Switch

The console's CC Switch option on the API Keys page can also import Gemini: set Application to Gemini, choose a Primary Model, and click Open CC Switch. The imported address is https://codaapi.com. See the CC Switch page for the full steps (Not tested).

Check that it works

Run the -p command above; a normal answer means it works. The request and its charge show up in the console's Usage Logs.

Common problems:

  • Invalid auth method selected: API-key authentication isn't selected in ~/.gemini/settings.json; see step 2 above.
  • 401: GEMINI_API_KEY isn't set or is wrong. See Troubleshooting for how to check the key.
  • 404 saying the model is not configured: the model name is wrong, or the model isn't in your key's group. Check it in Model Square.
  • 503 saying no channel is available: the model has no available channel right now. Try again later.
  • Requests go to Google's official address: GOOGLE_GEMINI_BASE_URL isn't set in your terminal, or you didn't open a new terminal after setting it.

Updated