Skip to content

Configure Gemini CLI ​

Gemini CLI ↗ is Google's open-source AI coding command-line tool. LAYSO AI provides a Gemini-compatible gateway so one API key can access platform models.

One key for every platform model

Models are billed at the current price shown on LAYSO AI models and pricing. Every successful request has an itemized charge; failed tasks are not charged.

Configuration steps ​

Step 1: Install Gemini CLI ​

Node.js 20 or later is required. macOS, Windows, and Linux / WSL use the same npm command:

bash
npm install -g @google/gemini-cli
gemini --version

The npm summary confirms that the install command completed. Then run gemini --version; a successfully printed version confirms that Gemini CLI is available.

Step 2: Get an API key and model ID ​

  1. Create and copy a key from the LAYSO AI API Keys page ↗.
  2. Open LAYSO AI models and pricing ↗, select a model, and copy its exact model ID.

Do not guess model aliases. Never put a real API key in a project file or commit it to Git.

Step 3: Configure LAYSO AI ​

Gemini CLI automatically loads .gemini/.env from the current user's home directory. All three operating systems use the same content:

dotenv
GEMINI_API_KEY=sk-...
GOOGLE_GEMINI_BASE_URL=https://api.layso.ai
GEMINI_MODEL=<MODEL_ID>

Replace sk-... with the complete LAYSO AI API key and <MODEL_ID> with the exact ID from the pricing page. Keep the Base URL at the root https://api.layso.ai; do not append /v1, /v1beta, or /gemini.

macOS ​

Configuration file: /Users/<username>/.gemini/.env (the same as ~/.gemini/.env).

bash
mkdir -p ~/.gemini
nano ~/.gemini/.env
chmod 600 ~/.gemini/.env

Windows ​

Configuration file: C:\Users\<username>\.gemini\.env ($HOME\.gemini\.env in PowerShell).

powershell
New-Item -ItemType Directory -Force "$HOME\.gemini"
notepad "$HOME\.gemini\.env"

When saving, make sure the filename is .env, not .env.txt.

Linux / WSL ​

Configuration file: /home/<username>/.gemini/.env (the same as ~/.gemini/.env).

bash
mkdir -p ~/.gemini
nano ~/.gemini/.env
chmod 600 ~/.gemini/.env

WSL uses the Linux home directory, not the Windows user directory. A project-level .env may take precedence over the user configuration, so check the current project when troubleshooting.

Step 4: Start and verify ​

Close any old Gemini CLI session, then restart it:

bash
gemini

If the first launch asks for an authentication method, choose Use Gemini API key. The header should show that authentication was completed with gemini-api-key. In the interactive session, send:

text
Introduce yourself in one sentence and tell me the current model name.

You can also make a non-interactive request:

bash
gemini -p "Introduce yourself in one sentence"

After the request succeeds, verify its model, token use, and itemized charge in LAYSO AI task details.

Configuration reference ​

SettingPurposeLAYSO AI value
GEMINI_API_KEYAuthenticates Gemini CLI requestsGet it from the API Keys page
GOOGLE_GEMINI_BASE_URLOverrides the Gemini API root and enables gateway modehttps://api.layso.ai
GEMINI_MODELSelects the default modelCopy the exact ID from the pricing page

Current Gemini CLI releases use the custom gateway when GOOGLE_GEMINI_BASE_URL is set. You do not need to put non-standard apiKey or baseUrl fields in settings.json.

Switch models ​

Copy a new exact model ID from LAYSO AI models and pricing ↗, then update .gemini/.env:

dotenv
GEMINI_MODEL=<NEW_MODEL_ID>

Fully quit and restart Gemini CLI after saving.

Available models ​

One LAYSO AI API key can access platform models. Refer to LAYSO AI models and pricing for model names, capabilities, context length, and current prices.

Use cases ​

  • Code generation and review: Read projects, edit files, run commands, and explain code.
  • Long-file analysis: Analyze large codebases, logs, and documents.
  • Multimodal tasks: Analyze images or documents when supported by the selected model.
  • Automation: Use non-interactive mode for scripted prompts.

Authentication and troubleshooting ​

SymptomResolution
401 / 403Check that GEMINI_API_KEY in .gemini/.env is complete and contains no extra spaces or line breaks
404Keep GOOGLE_GEMINI_BASE_URL=https://api.layso.ai; do not append a protocol path
Unknown modelCopy the exact model ID again from the pricing page
Requests still go to GoogleCheck the spelling of GOOGLE_GEMINI_BASE_URL, fully quit Gemini CLI, and restart it
Configuration is ignoredCheck for a higher-priority .env or .gemini/settings.json in the current project
No charge recordConfirm that the task succeeded; failed tasks are not charged

Security ​

  • Never expose a complete API key in screenshots, logs, chat messages, or Git repositories.
  • Do not copy the user-level .gemini/.env into a project directory.
  • Use a short prompt for the first test, then confirm the model and billing details before starting a long task.

LAYSO AI API 文档