Skip to main content

Overview

Gemini CLI is Google’s official command-line tool that allows you to interact directly with Gemini AI models in your terminal. Through API易, you can:
  • 🚀 Quickly call Gemini models in terminal
  • 💻 AI-assisted programming and code generation
  • 🔍 Code review and optimization suggestions
  • 📝 Technical Q&A and documentation generation
  • 🌐 Cross-platform support (Linux, macOS, Windows)
Why Choose API易?Using Gemini CLI through API易 provides more stable network connections, better pricing, and 24/7 technical support.

Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • npm or yarn package manager
  • API易 account and API Key

Step 1: Install Gemini CLI

# Check Node.js version
node --version  # Must be >= 18

# Install Gemini CLI globally
npm install -g @google/gemini-cli

# Verify installation
gemini --version

Step 2: Get API易 API Key

1

Register/Login to API易

Visit api.apiyi.com to register or login
2

Create API Key

Go to dashboard “Token Management” page (api.apiyi.com/token) and click “Create New Token”
3

Copy Key

Copy the generated API Key (format: sk-***) and keep it safe

Step 3: Configure Environment Variables

Important Configuration: GOOGLE_GEMINI_BASE_URL must be set to https://api.apiyi.com without any additional paths (like /v1 or /gemini), otherwise connection will fail.
# Edit .zshrc file
nano ~/.zshrc

# Add these environment variables
export GOOGLE_GEMINI_BASE_URL="https://api.apiyi.com"
export GEMINI_API_KEY="sk-your-api-key"  # Replace with your API易 key

# Reload configuration
source ~/.zshrc

Step 4: Initialize and Test

1

Launch Gemini CLI

gemini
2

First-time Authentication

In the interactive interface, type:
/auth
Select: Gemini API Key (AI Studio)
3

Test Connection

# Simple test
gemini "Hello, test connection"

# Programming-related test
gemini "Explain how React Hooks work"
gemini "Write a Python function to calculate Fibonacci sequence"

Core Features

Code Generation

gemini "Write a quick sort algorithm in Python with detailed comments"
Example Output:
def quick_sort(arr):
    """
    Quick sort algorithm
    Time complexity: Average O(n log n), Worst O(n²)
    Space complexity: O(log n)
    """
    if len(arr) <= 1:
        return arr

    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]

    return quick_sort(left) + middle + quick_sort(right)

Code Review

# Review code quality
gemini "Review the following code for performance issues and potential bugs:
[paste your code]
"

# Security audit
gemini "Check this code for security vulnerabilities, especially SQL injection and XSS"

# Best practices
gemini "What can be improved in this React component? Does it follow best practices?"

Technical Q&A

# Concept explanation
gemini "Explain JavaScript closures with practical use cases"

# Error troubleshooting
gemini "Why isn't my Promise being resolved correctly?"

# Performance optimization
gemini "How to optimize React component rendering performance?"

# Architecture design
gemini "Compare microservices vs monolithic architecture"

Documentation Generation

# Generate README
gemini "Generate a professional README.md for my Node.js library with installation, usage, and API docs"

# API documentation
gemini "Generate OpenAPI 3.0 spec documentation for this REST API endpoint"

# Code comments
gemini "Add detailed JSDoc comments to the following code"

Interactive Commands

In Gemini CLI interactive mode, you can use these commands:
CommandDescriptionExample
/authRe-authenticate/auth
/modelSwitch model/model gemini-3-pro-preview
/clearClear conversation history/clear
/helpShow help information/help
/exitExit CLI/exit or Ctrl+C
/saveSave conversation to file/save conversation.txt
Model Switching: Use /model command to switch between different Gemini models like gemini-3-pro-preview, gemini-2.5-flash, gemini-2.5-pro, etc.

Supported Models

Through API易, you can use the latest Gemini models:
ModelUse CaseFeatures
gemini-3-pro-previewHigh-quality code, complex reasoning🏆 Top performance, #1 on LMArena leaderboard
gemini-3-pro-preview-thinkingUltra-complex reasoning, algorithm design🧠 Chain-of-thought output, deep reasoning

Gemini 2.5 Series

ModelUse CaseFeatures
gemini-2.5-proProfessional code generation⚡ High performance, 1M context
gemini-2.5-flashFast response, daily development🚀 Fast speed, low cost
gemini-2.5-flash-liteLightweight tasks, batch calls💰 Ultra-low cost, high-frequency
Recommended Configuration:
  • Complex programming, architecture design: gemini-3-pro-preview
  • Daily code generation, Q&A: gemini-2.5-flash
  • Batch processing, rapid iteration: gemini-2.5-flash-lite

View Complete Model List

View all Gemini models supported by API易, detailed pricing and performance comparison

Advanced Usage

VS Code Integration

Use Gemini CLI extension in VS Code:
{
  "gemini.apiKey": "sk-your-api-key",
  "gemini.baseUrl": "https://api.apiyi.com",
  "gemini.model": "gemini-3-pro-preview",
  "gemini.temperature": 0.7,
  "gemini.maxTokens": 4000
}

GitHub Actions Integration

Automated code review:
name: Gemini Code Review
on:
  pull_request:
    branches: [ main ]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version: '18'

      - name: Install Gemini CLI
        run: npm install -g @google/gemini-cli

      - name: Run Code Review
        env:
          GEMINI_API_KEY: \${{ secrets.GEMINI_API_KEY }}
          GOOGLE_GEMINI_BASE_URL: https://api.apiyi.com
        run: |
          gemini "Review this Pull Request for code quality, security, and performance:
          $(git diff origin/main...HEAD)"

Batch Scripts

Create automation scripts:
#!/bin/bash

# Batch code review
for file in src/**/*.js; do
  echo "Reviewing $file..."
  gemini "Review code quality of $file" < "$file"
done

# Generate project documentation
gemini "Generate technical documentation outline for the entire project" < README.md

FAQ

Checklist:
  1. Verify environment variables:
    echo $GOOGLE_GEMINI_BASE_URL
    echo $GEMINI_API_KEY
    
    Should output:
    • GOOGLE_GEMINI_BASE_URL: https://api.apiyi.com (no /v1 or other paths)
    • GEMINI_API_KEY: Complete key starting with sk-
  2. Reload environment variables:
    source ~/.zshrc  # or source ~/.bashrc
    
  3. Restart terminal: Close and reopen terminal completely
  4. Verify API Key: Login to API易 dashboard to confirm key is valid with sufficient balance
Use /model command in interactive mode:
/model gemini-3-pro-preview
/model gemini-3-pro-preview-thinking
/model gemini-2.5-flash
Or specify directly in command:
gemini --model gemini-3-pro-preview "your question"
gemini --model gemini-2.5-flash "quick test"
Method 1: Use /save command
/save conversation-2025-01-01.txt
Method 2: Redirect output
gemini "your question" > output.txt
gemini "your question" | tee output.txt  # Display and save
Method 3: Use session management
gemini --session my-project "continue previous discussion"
Recommended: Use nvm to manage Node.js versions:
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Install Node.js 18+
nvm install 18
nvm use 18
nvm alias default 18

# Verify version
node --version
Possible causes and solutions:
  1. Network issues: API易 provides optimized domestic nodes, usually fast
  2. Model selection: Use gemini-2.5-flash or gemini-2.5-flash-lite for fastest response
  3. Token limit: Reduce complexity of single request
  4. Concurrent requests: Avoid sending too many requests simultaneously
Test connection speed:
time gemini --model gemini-2.5-flash "Hello"
Recommended: Use PowerShell:
  1. Install Node.js (download installer from official website)
  2. Run PowerShell as administrator
  3. Set environment variables:
    [System.Environment]::SetEnvironmentVariable('GOOGLE_GEMINI_BASE_URL', 'https://api.apiyi.com', 'User')
    [System.Environment]::SetEnvironmentVariable('GEMINI_API_KEY', 'sk-your-key', 'User')
    
  4. Restart PowerShell
  5. Install and use Gemini CLI
Or use WSL (Windows Subsystem for Linux) for better experience.

Best Practices

Prompt Optimization

Be Specific

❌ “Optimize this code”✅ “Optimize this code for performance, focusing on loop efficiency and memory usage”

Provide Context

❌ “What’s wrong with this function?”✅ “This is a user login function encountering async errors, help me find the issue”

Step-by-Step

❌ “Help me complete the entire project”✅ “Step 1: Design database models; Step 2: Create API routes; Step 3: …”

Request Examples

❌ “Explain closures”✅ “Explain JavaScript closures with 3 practical use cases and code examples”

Workflow Recommendations

1

Define Problem

Clearly describe the problem to solve or feature to implement
2

Get Solution

Use Gemini CLI to generate initial solution or code
3

Review & Optimize

Ask AI to review its own code and find potential issues
4

Iterate

Gradually optimize based on feedback until requirements are met
5

Add Documentation

Generate necessary comments and documentation

Pricing

Cost of using Gemini models through API易 depends on your chosen model and usage.

View Detailed Pricing

View detailed pricing and cost-effectiveness comparison for all Gemini models
API易 offers recharge bonuses: the more you recharge, the higher the bonus (10%-22%). First-time recharge gets extra bonus. View recharge promotion details.

Get Help

Technical Support

WeChat: 8765058Technical consultation, usage guidance

Email Inquiry

Customer Service: [email protected]Business: [email protected]
Quick Start: Follow the “Quick Start” section above to complete setup and start using Gemini CLI in 5 minutes!