gemini-web2api — Turn Google Gemini's Web UI Into a Free OpenAI-Compatible API
gemini-web2api — Turn Google Gemini's Web UI Into a Free OpenAI-Compatible API
Google Gemini's web interface is powerful — it offers flash-thinking models, long context windows, and built-in web search — all free of charge. But it's stuck in a browser. You can't call it from your code, hook it up to an AI client like Cherry Studio or Open Interpreter, or use it with the OpenAI SDK.
gemini-web2api changes that. It's a single Python file that reverse-engineers Gemini's internal StreamGenerate protocol and exposes it as a standard /v1/chat/completions endpoint. Drop it behind any OpenAI-compatible client and you get Gemini's latest models through a familiar API — with tool calling, streaming, and configurable thinking depth.
Why It's Trending
In late May 2026, Sophomoresty/gemini-web2api surged to over 1,400 GitHub stars in its first week. The appeal is immediate:
- Zero API cost — uses Gemini's free web access, not the paid API
- OpenAI drop-in — no code changes needed for existing OpenAI SDK clients
- Single file — one Python script, one optional dependency (
httpx) - Gemini's best models — Flash, Flash Thinking (20k+ char output), and Pro
- Tool/function calling — full OpenAI-format tool support through Gemini
As AI coding assistants proliferate (Claude Code, Codex, Gemini CLI, OpenCode), the need for a free, local-first API backend has never been greater. gemini-web2api fills that gap.
Architecture Overview
Here's how gemini-web2api bridges your tools to Google Gemini's web backend:
On the left, any OpenAI-compatible client (Cherry Studio, Open Interpreter, your own app) sends standard API calls to the proxy. gemini-web2api translates those requests into Gemini's internal payload format and relays them to Google's StreamGenerate endpoint. The response is converted back to OpenAI format and streamed back via SSE. Optionally, a Gemini Advanced cookie can be provided for Pro model routing.
Prerequisites
- A server or machine with Python 3.8+
- Network access to
gemini.google.com(a proxy/VPN may be needed in some regions) - Optionally: a Gemini Advanced account if you want Pro model access
Quick Start — 30 Seconds
pip install httpx
python gemini_web2api.py
That's it. The server starts at http://localhost:8081/v1 and is immediately usable.
Configuration
Create a config.json in the same directory as the script:
{
"port": 8081,
"host": "0.0.0.0",
"api_keys": [],
"cookie_file": null,
"proxy": null,
"log_requests": true
}
When api_keys is empty, authentication is disabled. To secure the server, add one or more API keys:
{
"api_keys": ["sk-my-secret-key"]
}
Then all requests must include Authorization: Bearer <your-api-key>.
Using With Any OpenAI Client
curl
curl http://localhost:8081/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gemini-3.5-flash","messages":[{"role":"user","content":"Hello!"}]}'
OpenAI Python SDK
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8081/v1",
api_key="sk-your-key"
)
response = client.chat.completions.create(
model="gemini-3.5-flash-thinking",
messages=[{"role": "user", "content": "Explain quantum computing in 3 sentences"}]
)
print(response.choices[0].message.content)
Cherry Studio / ChatBox
| Field | Value |
|---|---|
| Base URL | http://localhost:8081/v1 |
| API Key | any key from config.json |
| Model | gemini-3.5-flash-thinking |
Gemini CLI
export GEMINI_API_KEY=sk-your-key
export GOOGLE_GEMINI_BASE_URL=http://localhost:8081
gemini
Available Models
- gemini-3.5-flash — Fast, general-purpose (~12k chars output)
- gemini-3.5-flash-thinking — Deep reasoning, longest output (~20k chars)
- gemini-3.5-flash-thinking-lite — Adaptive thinking depth (~15k chars)
- gemini-3.1-pro — Pro model (requires Gemini Advanced cookie for real routing)
- gemini-auto — Auto model selection
- gemini-flash-lite — Lightweight, fastest
Thinking Depth Control
Append @think=N to any model name to control thinking depth:
| Suffix | Depth |
|---|---|
@think=0 |
Deepest (default) |
@think=2 |
Medium |
@think=4 |
Shallowest |
Docker Deployment
cp config.example.json config.json
docker build -t gemini-web2api .
docker run -d --name gemini-web2api \
-p 8081:8081 \
-v ./config.json:/app/config.json \
gemini-web2api
Or with Docker Compose:
version: "3"
services:
gemini-web2api:
build: .
ports:
- "8081:8081"
volumes:
- ./config.json:/app/config.json
Setting Up Pro Access (Optional)
Anonymous access works for all Flash models. For true Pro routing, you need a Gemini Advanced subscription and a browser cookie:
- Log into
gemini.google.comwith your paid account - Export the cookies as a Netscape-format file
- Pass them to the server:
python gemini_web2api.py --cookie-file cookie.txt
Set "cookie_file": "/app/cookie.txt" in config.json for Docker deployments.
Tool/Function Calling
gemini-web2api supports OpenAI-format tool calling:
response = client.chat.completions.create(
model="gemini-3.5-flash",
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
tools=[{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}]
)
How It Works
gemini-web2api reverse-engineers Google Gemini's web StreamGenerate protocol. When you send an OpenAI-format request, the proxy:
- Extracts the model, messages, and tools from your request
- Constructs the internal Gemini payload — mapping your model choice to Gemini's
MODE_CATEGORYenum (field[79]) - Sends it to the same
StreamGenerateendpoint that powers the Gemini web app - Parses the streaming response and converts it back to OpenAI's chat completion format
The result is a transparent bridge that requires no Gemini API key — only network access to gemini.google.com.
Limitations
- No image input — Gemini's image upload uses a proprietary streaming RPC protocol (WIZ/ProcessFile) that can't be replicated in a standard HTTP proxy
- Single-turn per request — multi-turn context is simulated by including previous messages in the prompt
- Rate limits — Google may throttle high-frequency requests; the server retries automatically but sustained heavy use may be blocked
- No real Pro without a paid cookie — without a Gemini Advanced subscription cookie, the Pro label falls back to Flash
Verification Checklist
Before deploying, run these checks:
- Server starts:
python gemini_web2api.pyand it binds to port 8081 - Basic request works:
curl http://localhost:8081/v1/chat/completions -d '{"model":"gemini-3.5-flash","messages":[{"role":"user","content":"Say hello"}]}'returns a 200 with choices - Streaming works via the OpenAI SDK with
stream=True - Tool calling works with the function calling example above
- Configurable API keys are enforced when
api_keysis non-empty
Resources
- GitHub: Sophomoresty/gemini-web2api
- Google Gemini: gemini.google.com
- OpenAI API reference: platform.openai.com/docs/api-reference