
轻量级 Gemini Web 网关,具有与 OpenAI 兼容的 API 和与 Google 兼容的 API。部署单个
Lightweight Gemini Web gateway with OpenAI-compatible and Google-compatible APIs. Deploy the single Worker bundle to Cloudflare or run it with Docker, with optional API authentication and Gemini cookie-backed features.
You are reading the
mainbranch documentation. This is the lightweight, non-persistent edition. Need multiple persistent accounts and a management console? Seegemini-account-pool.
Choose an edition · Deploy to Cloudflare · Deploy with Docker · API examples
web2gem lets OpenAI-compatible and Google Gemini-compatible clients use Gemini Web through a familiar HTTP API. The main edition is intentionally simple: it has no account database or admin console, and optional authenticated Gemini features use one runtime GEMINI_COOKIE that is refreshed in memory when possible.
It works well for personal deployments, simple proxies, and users who prefer a small stateless runtime. Cloudflare Workers can use cloudflare:sockets for upstream transport when regular fetch paths are rate-limited; Docker uses standard fetch by default.
The main compatibility targets are:
| Surface | Status | Routes |
|---|---|---|
| OpenAI Chat Completions | Supported | POST /v1/chat/completions |
| OpenAI Responses | Supported | POST /v1/responses |
| OpenAI Models | Supported | GET /v1/models, GET /v1/models/{id} |
| Google Gemini generateContent | Supported | POST /v1beta/models/{model}:generateContent, POST /v1/models/{model}:generateContent |
| Google Gemini streamGenerateContent | Supported | POST /v1beta/models/{model}:streamGenerateContent, POST /v1/models/{model}:streamGenerateContent |
| Google Models | Supported | GET /v1beta/models, GET /v1beta/models/{model} |
| Health | Supported | GET / |
Both editions expose familiar OpenAI-compatible and Google-compatible APIs. They are released as separate branches, so choose the storage model that fits your deployment; neither branch is presented as an upgrade path for the other.
main |
gemini-account-pool |
|
|---|---|---|
| Best for | Lightweight personal or single-runtime deployments. | Shared or long-running deployments that need multiple managed accounts. |
| Gemini credentials | Optional single GEMINI_COOKIE in runtime secrets; refreshed state stays in memory. |
Multiple Gemini accounts stored persistently in D1. |
| Persistent storage | None required. | Requires GEMINI_DB; Docker uses the D1 HTTP binding. |
| Account management | Update the runtime secret when credentials change. | Built-in /admin WebUI plus /admin/accounts API. |
| Operations | Smallest setup and fewer moving parts. | Account selection, health state, cooldowns, refresh tracking, and redacted diagnostics. |
| Public API authentication | Optional API_KEYS. |
Optional API_KEYS, with a separate single ADMIN_KEY for management. |
Choose main if you want the simplest deployment and do not need a persistent account pool. Choose gemini-account-pool if you want to import and manage multiple accounts without storing them directly in Worker or container environment variables.
| Feature | Description |
|---|---|
| Ready-to-use Flash models | No authentication or configuration is required; deploy the single file to start using Flash models with no usage limits, completely free. |
| Tool calling | Converts tool definitions into prompt instructions and parses DSML/XML-style tool-call output back into compatible API responses. |
| Structured output | Validates and canonicalizes final JSON for non-streaming structured responses; streaming structured output is rejected by default. |
| Large context handling | With GEMINI_COOKIE configured, large prompt context can be uploaded as Gemini text attachments instead of remaining entirely inline. |
| Image generation | Supports explicit OpenAI image_generation metadata for non-streaming Chat/Responses requests, plus /v1/images/generations and /v1/images/edits; a Gemini cookie is required. |
| Image input handling | Resolves user-provided inline/base64 images through the Gemini provider path. The Worker does not fetch remote image or file URLs. |
| Generic file attachments | With a Gemini cookie, request-local input_file and inline non-image data can use Gemini Web upload references with arbitrary filenames and MIME types; persistent /v1/files storage is not implemented. |
| Worker and Docker deployment | Deploy the Worker bundle to Cloudflare Workers or self-host with Docker / Docker Compose; neither mode requires an account database on main. |
| Upstream socket transport | Workers prefer cloudflare:sockets when available; Docker uses standard fetch. |
Choose only the settings your deployment needs:
| Goal | Required setting |
|---|---|
| Try supported Flash routes | No Gemini secret is required. |
| Protect a shared endpoint | Set one or more API_KEYS. |
| Use real Pro routing | Set GEMINI_COOKIE; SAPISID is optional and can often be derived. |
| Generate or edit images | Set GEMINI_COOKIE. |
| Upload large prompt context as Gemini text attachments | Set GEMINI_COOKIE. |
| Run behind a custom forwarding origin | Set GEMINI_ORIGIN. |
Gemini Web is an upstream web protocol and may change without notice. This project is best suited to personal, research, and internal use. For persistent multi-account operation, choose the gemini-account-pool edition instead.
curl https://your-web2gem.example/Returns service status, version, and the model IDs currently exposed by the adapter.
curl https://your-web2gem.example/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"messages": [
{ "role": "user", "content": "Write a concise project summary." }
]
}'Set "stream": true to receive Server-Sent Events.
For image generation, send explicit OpenAI image-generation metadata with a non-streaming request. The Worker routes requests with either tool_choice: { "type": "image_generation" } or a tools[] entry { "type": "image_generation" } through a pass-through image path. This mode uses only user-authored prompt text plus user-provided inline/existing image inputs, rejects attachments-only prompts, and returns upstream text/images as data-image or URL markdown in Chat Completions. Remote image/file URLs are not fetched. GEMINI_COOKIE is required for image generation, image editing, and image byte fetching.
curl https://your-web2gem.example/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"messages": [{ "role": "user", "content": "Generate a small blue app icon." }],
"tool_choice": { "type": "image_generation" }
}'curl https://your-web2gem.example/v1/responses \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"input": "Explain what this worker does in one paragraph."
}'Responses image generation uses the same explicit metadata and returns image_generation_call output items with base64 result values when image bytes are available; URL-only image metadata is passed through as markdown output text. Streaming image generation is not supported.
POST /v1/images/generations and POST /v1/images/edits are supported as non-streaming image-generation routes. They do not require tools or tool_choice, but they still require GEMINI_COOKIE.
curl https://your-web2gem.example/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"prompt": "Generate a small blue app icon.",
"response_format": "b64_json"
}'Image edits require prompt plus at least one local image input. JSON and multipart edit inputs can use image, images, image_url, or input_image with inline base64/data URL image bytes. Remote http:// / https:// image URLs are rejected and are not fetched by the Worker. Image endpoints support only n: 1, default response_format to b64_json, also accept response_format: "url" for provider URLs, and reject stream: true.
curl https://your-web2gem.example/v1beta/models/gemini-3.5-flash:generateContent \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [{ "text": "Return a short deployment checklist." }]
}
]
}'For streaming, call :streamGenerateContent on the same model path.
web2gem exposes a fixed model map in src/models/index.ts.
| Model ID | Description |
|---|---|
gemini-3.5-flash |
Fast general-purpose model. |
gemini-3.5-flash-thinking |
Deep thinking mode with longer output. |
gemini-3.1-pro |
暂无开放 Issues,或尚未同步最近议题。