Skip to content

Gemini CLI Configuration Guide

Gemini CLI is Google’s official command-line tool, designed to give developers a powerful AI-assisted coding experience. It supports intelligent code generation, code analysis, debugging assistance, and more.

  • Intelligent code generation - Quickly generate high-quality code
  • Code analysis - Deeply understand and analyze code structure
  • Debugging assistant - Smartly detect and fix code issues
  • Documentation generation - Automatically generate code documentation
  • Command-line integration - Seamlessly integrate into your development workflow

:star: Which models can be used with Gemini CLI

Section titled “:star: Which models can be used with Gemini CLI”

All Gemini models on this site are supported in Gemini CLI

npm install -g @google/gemini-cli # macOS/Linux需sudo权限

Run the following commands in Terminal:

export GOOGLE_GEMINI_BASE_URL="https://api.4allapi.com"
export GEMINI_API_KEY="你的API密钥"
export GEMINI_MODEL="gemini-3-pro"

Add the following to your shell configuration file:

echo 'export GOOGLE_GEMINI_BASE_URL="https://api.4allapi.com"' >> ~/.zshrc
echo 'export GEMINI_API_KEY="你的API密钥"' >> ~/.zshrc
echo 'export GEMINI_MODEL="gemini-2.5-pro"' >> ~/.zshrc
source ~/.zshrc
echo 'export GOOGLE_GEMINI_BASE_URL="https://api.4allapi.com"' >> ~/.bash_profile
echo 'export GEMINI_API_KEY="你的API密钥"' >> ~/.bash_profile
echo 'export GEMINI_MODEL="gemini-2.5-pro"' >> ~/.bash_profile
source ~/.bash_profile

Verify in Terminal:

echo $GOOGLE_GEMINI_BASE_URL
echo $GEMINI_API_KEY
echo $GEMINI_MODEL

Run the following commands in PowerShell:

$env:GOOGLE_GEMINI_BASE_URL = "https://api.4allapi.com"
$env:GEMINI_API_KEY = "你的API密钥"
$env:GEMINI_MODEL = "gemini-3-pro"

Run the following commands in PowerShell:

# Set user-level environment variables (persistent)
[System.Environment]::SetEnvironmentVariable("GOOGLE_GEMINI_BASE_URL", "https://api.4allapi.com", [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable("GEMINI_API_KEY", "你的API密钥", [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable("GEMINI_MODEL", "gemini-2.5-pro", [System.EnvironmentVariableTarget]::User)

:bulb: After making these changes, you need to reopen the PowerShell window for them to take effect.

Verify in PowerShell:

echo $env:GOOGLE_GEMINI_BASE_URL
echo $env:GEMINI_API_KEY
echo $env:GEMINI_MODEL
gemini # Enter interactive mode
gemini -p "解释这段代码" @./src/utils.js # File analysis
gemini --media wireframe.png "转换为React组件" # Multimodal processing
# View command help
/quit # Exit and show session statistics
/chat save feature_dev # Save current session
/chat resume feature_dev # Resume session
!ls -la # Run a system command
/tools # Show available tools
gemini review --staged-files --format=checklist # Git integration
gemini -p "@./ 总结项目架构" # Analyze the entire directory
gemini -p "@src/components/Button.jsx 生成单元测试" # Specific file
gemini "迁移Django项目到Python3.12" # Break down complex tasks

Advanced Memory Management (/memory Command)

Section titled “Advanced Memory Management (/memory Command)”
CommandFunctionUse case
/memory addAdd a new instructiongemini /memory add “Always reply in Chinese”
/memory showShow current memoryVerify AI context
/memory refreshReload the configuration fileAfter updating GEMINI.md
1. Create GEMINI.md to define project rules:
Section titled “1. Create GEMINI.md to define project rules:”
# 项目规范
- 使用TypeScript严格模式
- 函数命名:camelCase
- API响应格式:{ data, error }
/memory refresh # Reload all configuration
/memory show # Verify loaded content

Supports automatic scanning of multi-level directories; enterprise projects can define unified team standards

# Enable checkpointing at startup
gemini --checkpointing
# After performing operations that may modify files
/restore # View recoverable checkpoints
# Restore to a specific state
/restore checkpoint_42
  1. Roll back after a failed code-generation experiment
  2. Recover from file editing mistakes
  3. Create safety snapshots before batch operations
Error typeSymptomSolution
Authentication failureAPI key not foundCheck environment variables or reset config.json
Quota exceeded429 Too Many RequestsSwitch to another model or wait
Context overflowNo clear error code (performance degradation)Reduce input size / process in chunks
File creation failedInsufficient permissionsRun with administrator privileges or check directory permissions
Network errorConnection timed out1. Verify the proxy 2. Use curl to test API reachability
gemini -d # Enable verbose debug mode
/stats # View resource usage

4All API · One-stop AI large model API aggregation platform | Pricing | Contact us

© 2025 4All API. All rights reserved.