Skip to main content

Gemini CLI Proxy

Python 3.12+ License: MIT

Wrap Gemini CLI as an OpenAI-compatible API service, allowing you to enjoy the free Gemini 2.5 Pro model through API!

English | 简体中文

✨ Features

  • 🔌 OpenAI API Compatible: Implements /v1/chat/completions endpoint
  • 🚀 Quick Setup: Zero-config run with uvx
  • ⚡ High Performance: Built on FastAPI + asyncio with concurrent request support

🚀 Quick Start

Network Configuration

Since Gemini needs to access Google services, you may need to configure terminal proxy in certain network environments:

# Configure proxy (adjust according to your proxy server)
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890  
export all_proxy=socks5://127.0.0.1:7890

Install Gemini CLI

Install Gemini CLI:

npm install -g @google/gemini-cli

After installation, use the gemini command to run Gemini CLI. You need to start it once first for login and initial configuration.

After configuration is complete, please confirm you can successfully run the following command:

gemini -p "Hello, Gemini"

Start Gemini CLI Proxy

Method 1: Direct startup

uvx gemini-cli-proxy

Method 2: Clone this repository and run:

uv run gemini-cli-proxy

Gemini CLI Proxy listens on port 8765 by default. You can customize the startup port with the --port parameter.

After startup, test the service with curl:

curl http://localhost:8765/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer dummy-key" \
  -d '{
    "model": "gemini-2.5-pro",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Usage Examples

OpenAI Client

from openai import OpenAI

client = OpenAI(
    base_url='http://localhost:8765/v1',
    api_key='dummy-key'  # Any string works
)

response = client.chat.completions.create(
    model='gemini-2.5-pro',
    messages=[
        {'role': 'user', 'content': 'Hello!'}
    ],
)

print(response.choices[0].message.content)

Cherry Studio

Add Model Provider in Cherry Studio settings:

  • Provider Type: OpenAI
  • API Host: http://localhost:8765
  • API Key: Any string works
  • Model Name: gemini-2.5-pro or gemini-2.5-flash

Cherry Studio Config 1

Cherry Studio Config 2

⚙️ Configuration Options

View command line parameters:

gemini-cli-proxy --help

Available options:

  • --host: Server host address (default: 127.0.0.1)
  • --port: Server port (default: 8765)
  • --rate-limit: Max requests per minute (default: 60)
  • --max-concurrency: Max concurrent subprocesses (default: 4)
  • --timeout: Gemini CLI command timeout in seconds (default: 30.0)
  • --debug: Enable debug mode (enables debug logging and file watching)

❓ FAQ

Q: Why do requests keep timing out?

A: This is usually a network connectivity issue. Gemini needs to access Google services, which may require proxy configuration in certain regions:

# Configure proxy (adjust according to your proxy server)
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890

# Then start the service
uvx gemini-cli-proxy

📄 License

MIT License

🤝 Contributing

Issues and Pull Requests are welcome!

Metadata

Release files for gemini-cli-proxy 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gemini-cli-proxy 1.1.0
File Size Uploaded Provenance
gemini_cli_proxy-1.1.0.tar.gz 584.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gemini-cli-proxy 1.1.0
File Interpreter ABI Platform
gemini_cli_proxy-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 597.8 kB

Release files / gemini_cli_proxy-1.1.0.tar.gz

Download URL gemini_cli_proxy-1.1.0.tar.gz
Size 584.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5ba4639bd1b7a429177f2505621b828e32701e88b6053a1702634d7adb27a6ed
BLAKE2b-256 checksum
How to use checksums
3de6a97b43b4e3fb500b9fdc1bb53798f1f8994e256bf95e0847dfccb1ceb32e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / gemini_cli_proxy-1.1.0-py3-none-any.whl

Download URL gemini_cli_proxy-1.1.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd70b16dcc4e768a7c4eb68903a8f7547fbecf2dc0b50f13ff5c688c07d1c9bc
BLAKE2b-256 checksum
How to use checksums
23555a2a28808540e5d7a5e0c4cae64da20db5820c7c0697e537bc184bd59ecc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Security for gemini-cli-proxy 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page