Skip to main content

OpenAI-compatible API wrapper for Gemini CLI

Project description

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

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)
  • --log-level: Log level (debug/info/warning/error/critical)
  • --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

❓ 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemini_cli_proxy-1.0.3.tar.gz (582.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemini_cli_proxy-1.0.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file gemini_cli_proxy-1.0.3.tar.gz.

File metadata

  • Download URL: gemini_cli_proxy-1.0.3.tar.gz
  • Upload date:
  • Size: 582.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for gemini_cli_proxy-1.0.3.tar.gz
Algorithm Hash digest
SHA256 10af7e75df0bc014c762091167df8a241cc6b5a65de77ff6fd7cbf58881963d0
MD5 a3026fb7e204bf1b6b4d10eb18d334be
BLAKE2b-256 570c3b33d423e8c5315732c43a0d9cf1712c101962c460cce6ddd92240f8978e

See more details on using hashes here.

File details

Details for the file gemini_cli_proxy-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_cli_proxy-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5d333c2331d9e016db0c13aa3ddf8980f3f14446d5b223ca1b807be8b2ddee99
MD5 c1ece50a99d125734e7ce6523f6be60a
BLAKE2b-256 e78e9ab322cc0a3ff9e293717fd2fac3180337a37ab6a31f1164a765359bbf06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page