This program is a wrapper for Gemini CLI that can serve Google Gemini 2.5 Pro (or Flash) through an OpenAI-compatible API. It works plug-and-play with clients that already speak OpenAI like SillyTavern, llama.cpp, LangChain, VS Code's Cline extension, etc.
| ✔ | Feature | Notes |
|---|---|---|
/v1/chat/completions |
Non-stream & stream (SSE) | Works with curl, ST, LangChain… |
| Vision support | image_url → Gemini inlineData |
|
| Function / Tool calling | OpenAI "functions" → Gemini Tool Registry | |
| Reasoning / chain-of-thought | Sends enable_thoughts:true, streams <think> chunks |
ST shows gray bubbles |
| 1M token context | Proxy auto-elevates Gemini CLI's default 200k limit | |
| CORS | Enabled (*) by default |
Ready for browser apps |
git clone https://github.com/DouveAlexandre/GeminiCLI-Proxy2OpenAIAPI
cd GeminiCLI-Proxy2OpenAIAPI
npm i
npm start # starts the server (runs on port 11434 by default)Alternatively, you can use the provided Dockerfile to build a Docker image.
docker build --tag "GeminiCLI-Proxy2OpenAIAPI" .
docker run -p 11434:80 -e GEMINI_API_KEY=your_key_here GeminiCLI-Proxy2OpenAIAPIThe application uses an .env file for configuration. Create an .env file in the project root with the following variables:
# Port where the server will run
PORT=11434
# Authentication type - can be 'oauth-personal', 'gemini-api-key', or 'vertex-ai'
AUTH_TYPE=oauth-personal
# Path to OAuth credentials (only for AUTH_TYPE='oauth-personal')
GOOGLE_APPLICATION_CREDENTIALS=C:\Users\your_user\.gemini\oauth_creds.json
# Gemini API Key (only for AUTH_TYPE='gemini-api-key')
GEMINI_API_KEY=
# Model to be used - 'gemini-2.5-flash' or 'gemini-2.5-pro'
# Leave empty to use CLI default model
MODEL=AUTH_TYPE=oauth-personal
GOOGLE_APPLICATION_CREDENTIALS=C:\Users\your_user\.gemini\oauth_creds.json- Advantages: Free access to Gemini 2.5 Pro
- How to configure: Log in to your Google account through Gemini CLI
- Requirements: Gemini CLI configured with OAuth
AUTH_TYPE=gemini-api-key
GEMINI_API_KEY=your_api_key_here- Advantages: Simpler to configure
- How to obtain: Visit Google AI Studio
- Requirements: Valid Google AI API key
AUTH_TYPE=vertex-ai- Usage: For corporate environments with Vertex AI
- Requirements: Additional Google Cloud configuration
# To use Gemini 2.5 Flash (faster, less accurate)
MODEL=gemini-2.5-flash
# To use Gemini 2.5 Pro (slower, more accurate)
MODEL=gemini-2.5-pro
# Leave empty to use default model
MODEL=- Clone the repository and install dependencies:
git clone https://github.com/DouveAlexandre/GeminiCLI-Proxy2OpenAIAPI
cd GeminiCLI-Proxy2OpenAIAPI
npm install-
Create the
.envfile with your settings (see section above) -
Start the server:
npm startThe server will be available at http://localhost:11434
curl -X POST http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro",
"messages": [{"role": "user", "content": "Hello Gemini!"}]
}'- Go to API Connections
- Select Chat Completion (OpenAI, Claude, Window/OpenRouter, Scale)
- Configure:
- API: OpenAI
- API Base URL:
http://127.0.0.1:11434/v1/chat/completions - API Key: any value (not used)
- Model:
gemini-2.5-proorgemini-2.5-flash
- Install the Cline extension
- Configure:
- Provider: OpenAI Compatible
- Base URL:
http://localhost:11434/v1/chat/completions - API Key: any value
- Model:
gemini-2.5-pro
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="http://localhost:11434/v1/chat/completions",
api_key="any-value",
model="gemini-2.5-pro-latest"
)
response = llm.invoke("Hello, how are you?")
print(response.content)curl -X POST http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro-latest",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
]
}]
}'curl -X POST http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro-latest",
"messages": [{"role": "user", "content": "Tell me a story"}],
"stream": true
}'curl -X POST http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro-latest",
"messages": [{"role": "user", "content": "What's the weather today?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "Location"}
}
}
}
}]
}'- Check if the path in
GOOGLE_APPLICATION_CREDENTIALSis correct - Run
gemini authin the terminal to reauthenticate
- Check if the key in
GEMINI_API_KEYis valid - Confirm that
AUTH_TYPE=gemini-api-key
- Check if the port specified in
PORTis available - Confirm that all dependencies were installed with
npm install
- Use
gemini-2.5-proorgemini-2.5-flashas the model name - Leave
MODELempty in .env to use the default
MIT – free for personal and commercial use. Fork of https://huggingface.co/engineofperplexity/gemini-openai-proxy