Skip to content

Gemini CLI Complete Setup Guide: Installation, configuration, third-party providers, and cost optimization | gemini cli tutorial

Notifications You must be signed in to change notification settings

xujfcn/gemini-cli-setup-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Gemini CLI Complete Setup Guide 2026: Installation, Configuration & Cost Optimization

Last Updated: February 2026 | The most comprehensive Gemini CLI tutorial on the internet.

Table of Contents

What is Gemini CLI?

Gemini CLI is Google's command-line AI coding assistant powered by Gemini 2.5 Pro. It features a massive 1M+ token context window, multimodal input support (images, screenshots, diagrams), and MCP server integration. It's Google's answer to Claude Code and OpenAI Codex.

Key Features

  • 1M+ token context window — analyze entire codebases at once
  • Multimodal input — paste screenshots, diagrams, images
  • MCP server support — integrate with external tools
  • Free tier — generous free usage limits
  • Cross-platform — works on macOS, Linux, Windows

Installation

Via npm (Recommended)

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

Via pip

pip install gemini-cli

Via Homebrew (macOS)

brew install gemini-cli

Configuration

Default Setup (Google OAuth)

gemini auth login
# Opens browser for Google account authentication

API Key Setup

export GEMINI_API_KEY=your-google-api-key

Third-Party Provider Setup (Save 45%)

export GEMINI_API_BASE=https://crazyrouter.com/v1
export GEMINI_API_KEY=sk-your-crazyrouter-key

Using Third-Party Providers

Gemini CLI supports OpenAI-compatible API providers. Use Crazyrouter to:

  • Access Gemini at 55% of official pricing
  • Use the same API key for Claude, GPT, and Gemini
  • Get higher rate limits and auto-failover

Python Example

import openai

client = openai.OpenAI(
    base_url="https://crazyrouter.com/v1",
    api_key="sk-your-crazyrouter-key"
)

response = client.chat.completions.create(
    model="gemini-2.5-pro",
    messages=[{"role": "user", "content": "Explain this codebase"}]
)
print(response.choices[0].message.content)

cURL Example

curl https://crazyrouter.com/v1/chat/completions \
  -H "Authorization: Bearer sk-your-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-2.5-pro","messages":[{"role":"user","content":"Hello"}]}'

Pricing Comparison

Model Google Direct Crazyrouter Savings
Gemini 2.5 Pro $1.25 / $10.00 $0.69 / $5.50 45%
Gemini 2.5 Flash $0.15 / $0.60 $0.08 / $0.33 45%
Gemini 2.5 Flash Lite $0.075 / $0.30 $0.04 / $0.17 45%

Prices per 1M tokens (input / output)

Monthly Cost Estimate

Usage Level Google Direct Crazyrouter
Light (1M tokens/mo) $10 $5.50
Medium (10M tokens/mo) $100 $55
Heavy (50M tokens/mo) $500 $275

Tips & Tricks

  1. Use Flash for simple tasks — 10x cheaper than Pro, fast enough for most coding tasks
  2. Leverage the 1M context — paste entire repos for better understanding
  3. Combine with CC-SwitchCC-Switch lets you switch between Gemini, Claude, and GPT with one click

Gemini CLI vs Claude Code vs Codex

Feature Gemini CLI Claude Code Codex
Context Window 1M+ tokens 200K 128K
Free Tier Yes No Limited
Multimodal Yes Yes No
MCP Support Yes Yes No
Best For Large codebases Refactoring Quick edits

FAQ

Is Gemini CLI free?

Yes, there's a generous free tier. For heavier usage, use pay-as-you-go API pricing or a third-party provider like Crazyrouter for 45% savings.

Can I use Gemini CLI with a third-party provider?

Yes. Set GEMINI_API_BASE to your provider's endpoint (e.g., https://crazyrouter.com/v1).

How does Gemini CLI compare to Claude Code?

Gemini CLI has a larger context window (1M+ vs 200K) and a free tier. Claude Code has better code refactoring. Use both through Crazyrouter with one API key.

What models does Gemini CLI support?

Gemini 2.5 Pro, 2.5 Flash, 2.5 Flash Lite, and upcoming Gemini 3 models.


🔗 Links:

About

Gemini CLI Complete Setup Guide: Installation, configuration, third-party providers, and cost optimization | gemini cli tutorial

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published