[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-80606":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":9,"rankLanguage":9,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":9,"pushedAt":9,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":15,"starSnapshotCount":15,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},80606,"gemini-web2api","Sophomoresty\u002Fgemini-web2api","Sophomoresty","Convert Google Gemini web into OpenAI-compatible API. Zero auth, cross-platform, single file.",null,"Python",1690,408,11,4,0,31,303,1529,154,20.84,"MIT License",false,"main",true,[],"2026-06-12 02:04:04","# gemini-web2api\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"logo.png\" width=\"200\" alt=\"gemini-web2api logo\">\n\u003C\u002Fp>\n\n[中文文档](README_CN.md)\n\nConvert Google Gemini's web interface into an OpenAI-compatible API. Zero authentication, zero cost, cross-platform.\n\n## Features\n\n- **Optional API Keys**: no auth when `api_keys` is empty, OpenAI-style Bearer auth when configured\n- **OpenAI Compatible**: Drop-in replacement for `\u002Fv1\u002Fchat\u002Fcompletions` and `\u002Fv1\u002Fmodels`\n- **Tool Calling**: Full function calling support (OpenAI format)\n- **Multiple Models**: Flash, Flash Thinking (20k+ char output), Pro, Auto, Lite\n- **Thinking Depth**: Adjustable via `@think=N` suffix (0=deepest, 4=shallowest)\n- **Web Search**: Built-in internet access (Gemini's native search)\n- **Cross-Platform**: Pure Python, no dependencies beyond stdlib\n- **Streaming**: SSE streaming support\n- **Codex CLI**: Responses API (`\u002Fv1\u002Fresponses`) for OpenAI Codex integration\n- **Gemini CLI**: Google native API (`\u002Fv1beta\u002Fmodels`) for Gemini CLI compatibility\n\n## Quick Start\n\n```bash\npython gemini_web2api.py\n```\n\nServer starts at `http:\u002F\u002Flocalhost:8081\u002Fv1`.\n\n## Client Configuration\n\n### Cherry Studio \u002F ChatBox \u002F any OpenAI client\n\n| Field | Value |\n|-------|-------|\n| Base URL | `http:\u002F\u002Flocalhost:8081\u002Fv1` |\n| API Key | any `api_keys` value from `config.json`; anything if not configured |\n| Model | `gemini-3.5-flash-thinking` |\n\n### curl\n\n```bash\ncurl http:\u002F\u002Flocalhost:8081\u002Fv1\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer sk-your-key\" \\\n  -d '{\"model\":\"gemini-3.5-flash\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello!\"}]}'\n```\n\n### OpenAI Python SDK\n\n```python\nfrom openai import OpenAI\nclient = OpenAI(base_url=\"http:\u002F\u002Flocalhost:8081\u002Fv1\", api_key=\"sk-your-key\")\nresp = client.chat.completions.create(\n    model=\"gemini-3.5-flash-thinking\",\n    messages=[{\"role\": \"user\", \"content\": \"Explain quantum computing\"}]\n)\nprint(resp.choices[0].message.content)\n```\n\n### Gemini CLI\n\n```bash\nexport GEMINI_API_KEY=none\nexport GOOGLE_GEMINI_BASE_URL=http:\u002F\u002Flocalhost:8081\ngemini\n```\n\nSupports Google native API endpoints:\n- `GET \u002Fv1beta\u002Fmodels` — list models\n- `POST \u002Fv1beta\u002Fmodels\u002F{model}:generateContent` — non-streaming\n- `POST \u002Fv1beta\u002Fmodels\u002F{model}:streamGenerateContent` — streaming (SSE)\n\n## Available Models\n\n| Model | Description | Output |\n|-------|-------------|--------|\n| `gemini-3.5-flash` | Fast general-purpose | ~12k chars |\n| `gemini-3.5-flash-thinking` | Deep thinking, longest output | **~20k chars** |\n| `gemini-3.5-flash-thinking-lite` | Adaptive thinking depth | ~15k chars |\n| `gemini-3.1-pro` | Pro (needs cookie for real routing) | ~12k chars |\n| `gemini-auto` | Auto model selection | varies |\n| `gemini-flash-lite` | Lightweight fast | ~10k chars |\n\n### Thinking Depth\n\nAppend `@think=N` to any model name:\n\n```\ngemini-3.5-flash-thinking@think=0   # deepest (default)\ngemini-3.5-flash-thinking@think=2   # medium\ngemini-3.5-flash-thinking@think=4   # shallowest\n```\n\n## Optional: Cookie for Pro\n\nAnonymous access works for all models, but `gemini-3.1-pro` routes to Flash without authentication. To get real Pro routing, provide a cookie file:\n\n```bash\npython gemini_web2api.py --cookie-file cookie.txt\n```\n\n### How to get cookies\n\n1. Open Chrome, go to [gemini.google.com](https:\u002F\u002Fgemini.google.com) and sign in with any free Google account\n2. Open DevTools (F12) → Application → Cookies → `https:\u002F\u002Fgemini.google.com`\n3. Copy these cookie values: `SID`, `HSID`, `SSID`, `APISID`, `SAPISID`, `__Secure-1PSID`\n4. Create `cookie.txt` in this format:\n\n```\nSID=your_sid_value; HSID=your_hsid_value; SSID=your_ssid_value; APISID=your_apisid_value; SAPISID=your_sapisid_value; __Secure-1PSID=your_1psid_value\n```\n\nOr use the JSON format:\n```json\n{\"cookie\": \"SID=xxx; HSID=xxx; SSID=xxx; APISID=xxx; SAPISID=xxx; __Secure-1PSID=xxx\", \"sapisid\": \"your_sapisid_value\"}\n```\n\n**Alternative (browser extension)**: Use any \"Export Cookies\" extension to export cookies for `gemini.google.com` in Netscape format, then convert to the single-line format above.\n\nNo paid subscription needed — a free Google account is sufficient.\n\n## Configuration\n\nCreate `config.json` in the same directory:\n\n```json\n{\n  \"port\": 8081,\n  \"host\": \"0.0.0.0\",\n  \"retry_attempts\": 3,\n  \"retry_delay_sec\": 2,\n  \"request_timeout_sec\": 180,\n  \"api_keys\": [\"sk-your-key\"],\n  \"cookie_file\": null,\n  \"proxy\": null,\n  \"log_requests\": true\n}\n```\n\nWhen `api_keys` is `[]`, authentication is disabled. When one or more keys are set, `\u002Fv1\u002F*` endpoints require `Authorization: Bearer \u003Ckey>` or `x-api-key: \u003Ckey>`.\n\n## Docker\n\n```bash\ncp config.example.json config.json\ndocker build -t gemini-web2api .\ndocker run -d --name gemini-web2api -p 8081:8081 -v .\u002Fconfig.json:\u002Fapp\u002Fconfig.json gemini-web2api\n```\n\nOr use Docker Compose:\n\n```bash\ncp config.example.json config.json\ndocker compose up -d\n```\n\nTo mount a cookie file:\n\n```bash\ndocker run -d --name gemini-web2api -p 8081:8081 -v .\u002Fconfig.json:\u002Fapp\u002Fconfig.json -v .\u002Fcookie.txt:\u002Fapp\u002Fcookie.txt gemini-web2api\n```\n\nSet `\"cookie_file\": \"\u002Fapp\u002Fcookie.txt\"` in `config.json`.\n\n## Proxy\n\nIf you cannot access `gemini.google.com` directly (connection timeout), configure a proxy:\n\n**Method 1: CLI argument**\n```bash\npython gemini_web2api.py --proxy http:\u002F\u002F127.0.0.1:7890\n```\n\n**Method 2: config.json**\n```json\n{\"proxy\": \"http:\u002F\u002F127.0.0.1:7890\"}\n```\n\n**Method 3: Environment variable** (auto-detected)\n```bash\nexport HTTPS_PROXY=http:\u002F\u002F127.0.0.1:7890\npython gemini_web2api.py\n```\n\nWorks with Clash, V2Ray, Shadowsocks, or any HTTP proxy.\n\n## Tool Calling\n\n```python\nresp = client.chat.completions.create(\n    model=\"gemini-3.5-flash\",\n    messages=[{\"role\": \"user\", \"content\": \"What's the weather in Tokyo?\"}],\n    tools=[{\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"get_weather\",\n            \"description\": \"Get weather for a city\",\n            \"parameters\": {\"type\": \"object\", \"properties\": {\"city\": {\"type\": \"string\"}}, \"required\": [\"city\"]}\n        }\n    }]\n)\n```\n\n## Limitations\n\n- **No image\u002Fmultimodal input**: Gemini's image upload requires a proprietary streaming RPC protocol (WIZ\u002FProcessFile) that cannot be replicated in a standard HTTP proxy. Image inputs in messages will be ignored with a note.\n- **Not real Pro\u002FUltra**: Without a paid subscription cookie, `gemini-3.1-pro` routes to the same Flash model. The \"Pro\" label is a UI preference, not a backend model switch.\n- **Single-turn only**: Each request is an independent conversation. Multi-turn context is simulated by including previous messages in the prompt.\n- **Rate limits**: Google may throttle high-frequency requests. The server retries automatically but sustained heavy use may be blocked.\n\n## Requirements\n\n- Python 3.8+\n- No external dependencies (stdlib only)\n- Network access to `gemini.google.com` (proxy\u002FVPN may be needed in some regions)\n\n## How It Works\n\nThis tool reverse-engineers Google Gemini's web StreamGenerate protocol. It sends requests to the same endpoint that the Gemini web app uses, converting between OpenAI's API format and Gemini's internal protobuf-like format.\n\nThe model selection is controlled by field `[79]` in the request payload, mapped from Gemini's frontend JavaScript source (`MODE_CATEGORY` enum).\n\n## Acknowledgments\n\n- [GenericAgent](https:\u002F\u002Fgithub.com\u002Flsdefine\u002FGenericAgent) — 本项目核心开发依仗 GA 提供的 AI 能力\n- [linux.do](https:\u002F\u002Flinux.do) community\n- Inspired by the open-source API proxy ecosystem\n\n## License\n\nMIT\n","gemini-web2api 项目旨在将 Google Gemini 的网页界面转换为与 OpenAI 兼容的 API，无需认证且跨平台。其核心功能包括支持多种模型（如 Flash、Flash Thinking 等），具备可调思考深度和内置网络搜索能力，并兼容 OpenAI 标准接口如 `\u002Fv1\u002Fchat\u002Fcompletions` 和工具调用功能。此外，它还提供了流式处理支持及与 OpenAI Codex 的集成点。该项目纯 Python 实现，不依赖外部库，适用于需要快速搭建本地 AI 服务或希望在现有 OpenAI 客户端中无缝使用 Gemini 能力的场景。",2,"2026-06-11 04:01:21","CREATED_QUERY"]