OpenAI-compatible API wrapper for Gemini CLI
Project description
Gemini CLI Proxy
Wrap Gemini CLI as an OpenAI-compatible API service, allowing you to enjoy the free Gemini 2.5 Pro model through API!
✨ Features
- 🔌 OpenAI API Compatible: Implements
/v1/chat/completionsendpoint - 🚀 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-proorgemini-2.5-flash
⚙️ 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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gemini_cli_proxy-1.1.0.tar.gz.
File metadata
- Download URL: gemini_cli_proxy-1.1.0.tar.gz
- Upload date:
- Size: 584.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ba4639bd1b7a429177f2505621b828e32701e88b6053a1702634d7adb27a6ed
|
|
| MD5 |
e92fa703e1dcab94d00d949d0eea1001
|
|
| BLAKE2b-256 |
3de6a97b43b4e3fb500b9fdc1bb53798f1f8994e256bf95e0847dfccb1ceb32e
|
File details
Details for the file gemini_cli_proxy-1.1.0-py3-none-any.whl.
File metadata
- Download URL: gemini_cli_proxy-1.1.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd70b16dcc4e768a7c4eb68903a8f7547fbecf2dc0b50f13ff5c688c07d1c9bc
|
|
| MD5 |
19a58b8905533030e2f3bf59e3fae80a
|
|
| BLAKE2b-256 |
23555a2a28808540e5d7a5e0c4cae64da20db5820c7c0697e537bc184bd59ecc
|