zexadev/gemini-web2api-go
把 Google Gemini 网页反代成 OpenAI 兼容 API · Reverse Google Gemini's web protocol into an OpenAI-compatible API. Single binary, Chrome 146 fingerprint, SQLite, built-in admin dashboard.
gemini‑web2api‑go – Gemini Web ↔ OpenAI‑compatible API proxy
What it is
- A single‑binary Go server that reverse‑proxies the private browser‑based protocol used by Google Gemini’s web UI and re‑exposes it as a OpenAI‑compatible REST API (
/v1/chat/completions,/v1/models, etc.). - Because it talks to the web UI instead of the official Google Generative Language API, no Google API key or paid quota is required – the server can operate anonymously or with a logged‑in Google account (via cookies) to unlock extra Gemini features.
Key features
| Feature | Details |
|---|---|
| OpenAI‑compatible endpoints | /v1/chat/completions, /v1/models, /v1/responses, plus a /v1/videos endpoint that mimics OpenAI Sora’s async video generation. |
| Model support | gemini-3.6-flash, gemini-3.5-flash-lite (anonymous). With a valid Google cookie you also get gemini-3.1-pro, extended‑thinking variants, image/audio generation (gemini-image, gemini-music, gemini-canvas, gemini-video). |
| True streaming | For normal chat the server forwards each upstream frame as a delta chunk, giving low‑latency streaming. Tool‑calling requests are buffered and sent after the full response (required by Gemini). |
| Authentication | Bearer token or x‑api‑key (generated on first start, rotatable via the admin UI). |
| Rate‑limiting & proxy pool | Per‑IP concurrency, RPM and RPH limits; configurable proxy pool with automatic failure‑circuit‑breakers; each proxy gets its own quota slot. |
| Cookie pool | Stores multiple Google login cookies, rotates them per‑request, auto‑renews cookies every 10 min, and binds each cookie to a single outbound IP to avoid Google‑detected account sharing. |
| Persistence | SQLite by default (30‑day request logs, permanent aggregates). MySQL/PostgreSQL can be used by setting SQL_DSN. |
| Admin UI | A lightweight Chinese‑language web panel (/admin) for monitoring KPIs, viewing request metadata, managing the proxy and cookie pools, and changing runtime configuration without restarting. |
| MCP (web‑search) server | Exposes Gemini’s built‑in web‑search tool at /mcp so clients like Claude Desktop can call web_search(query) and receive a synthesized answer with source links. |
| Zero‑code deployment | Single binary for six platforms, Docker distroless image, and a Docker‑Compose starter. |
| Privacy‑first | Prompt and response bodies are never stored; only metadata (model, token counts, latency, status) is persisted. |
How to run
- Binary – download the appropriate release, make it executable and start it:
chmod +x gemini-web2api-go_* ./gemini-web2api-go_* --port 8083 --admin-token mytoken - Docker – one‑liner:
docker run -d --name gemini-web2api \ -p 127.0.0.1:8083:8083 \ -v "$PWD/data:/data" \ -e ADMIN_TOKEN=mytoken \ ghcr.io/zexadev/gemini-web2api-go:latest - Source –
go build -o gemini-web2api-go .and run the same flags.
Calling the API (any OpenAI‑compatible client works):
curl http://localhost:8083/v1/chat/completions \
-H "Authorization: Bearer sk-gemini-..." \
-H "Content-Type: application/json" \
-d '{"model":"gemini-3.6-flash","messages":[{"role":"user","content":"Hello!"}]}'
Or with the Python SDK:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8083/v1", api_key="sk-gemini-...")
resp = client.chat.completions.create(model="gemini-3.6-flash",
messages=[{"role":"user","content":"Explain quantum entanglement"}])
print(resp.choices[0].message.content)
When to add a Google cookie
- Anonymous mode only gives the two flash models and the built‑in web‑search tool.
- Adding a
SID/HSID/...cookie (via the admin UI or--cookie-file) unlocks:gemini-3.1-prowith reasoning chain (reasoning_content)- “thinking” extensions for the flash models
- multimodal generation (images, music, canvas, video)
- longer effective context (≈ 160 KB vs 130 KB) via automatic attachment of a
message.txtfile.
Limitations / gotchas
- The server only implements the OpenAI‑style endpoints; Gemini’s native
/v1betaendpoints are not supported. - Token limits are enforced on the raw UTF‑8 byte size of the request (default 128 KB). Exceeding it returns
context_length_exceededfor anonymous users; with a cookie the request is turned into a text attachment up to ≈ 160 KB. - Streaming works for normal chat; tool‑calling and
/v1/responsesare buffered because Gemini needs the full tool output before it can continue. - Proxy‑pool traffic uses Go’s standard library TLS fingerprint (not the Chrome 146 fingerprint used for direct connections). This does not materially affect capacity but is worth noting.
- Image/audio generation counts only the textual description toward
completion_tokens; the base64 payload is excluded. - The admin UI is Chinese‑only; the underlying API is language‑agnostic.
Typical use cases
- Run locally‑hosted LLM‑aware applications (ChatGPT‑style UI, LangChain agents, code assistants) without needing a Google Cloud billing account.
- Provide a drop‑in OpenAI endpoint for tools that only understand the OpenAI schema (e.g.,
newapi,Cherry Studio,Cursor,dify). - Enable Gemini’s web‑search tool for agents that support “MCP” (Claude Desktop/Code) via the
/mcpendpoint. - Experiment with Gemini’s multimodal models (image, music, canvas, video) behind a familiar OpenAI API surface.
TL;DR: gemini-web2api-go is a Go‑based reverse‑proxy that turns the private Gemini web UI protocol into a fully‑featured, OpenAI‑compatible API, with optional Google‑cookie support for premium Gemini models, built‑in rate‑limiting, proxy & cookie pools, and a tiny admin dashboard. It runs as a single binary or a distroless Docker container and requires no Google API key.
관련
- 프로젝트
- 프로젝트
- 프로젝트
- 프로젝트
- 프로젝트