Gemini Web2API - Deno Deploy Documentation
中文文档 | Cloudflare Docs | Netlify Docs | Vercel Docs Run Gemini Web2API on Deno Deploy for SSE streaming with raw TCP socket support — zero config, no server to maintain.The entrypoint is atdeno/deploy.js, a thin Deno adapter over the shared core insrc/(the same core used by the Cloudflare, Netlify and Vercel adapters). It starts an HTTP server withDeno.serve()— the API required by the current Deno Deploy platform (Deploy Classic, which accepted legacyserve(), was shut down on 2026-07-20).deno/sockets.jswrapsDeno.connectinto the socket shape the proxy pool expects, so the rotating proxy pool works on Deno too. Deno Deploy is a good fit because, like Cloudflare Workers (but unlike Netlify/Vercel Edge), Deno exposes raw TCP sockets (Deno.connect), so the full rotating proxy pool is available. And like Netlify Edge (but unlike Vercel), Deno’sfetch()natively tunnels throughHTTPS_PROXY/HTTP_PROXY/ALL_PROXYfor static outbound proxies.
Quick Deploy
Option 1: GitHub integration (recommended)
- Fork or push this repository to your GitHub account.
- Sign in at console.deno.com and create an organization (new Deno Deploy uses a separate account system from the retired Deploy Classic).
- Click + New App, select your GitHub repository, and grant the Deno Deploy GitHub app access if prompted.
- In Edit build config:
- Framework preset:
No Preset - Install command: (leave empty)
- Build command: (leave empty)
- Runtime mode:
Dynamic - Entrypoint:
deno/deploy.js
- Framework preset:
- (Optional) Add environment variables (see table below), choosing the Production/Development contexts.
- Click Create App. The build runs, warms up, and your API is live at
https://your-app-name.deno.net.
Option 2: Deno CLI
Thedeployctl CLI is sunset; the deno deploy subcommand replaces it (Deno 2.x includes it).
subsequent deploys of an existing app:
deno deploy —org your-org —app gemini-web2api —prod Environment variables can be managed from the CLI too:Environment Variables (Optional)
Configure these in Deno Deploy: app settings → Add/Edit environment variables (ordeno deploy env add).
TLS proxying note (Deno Deploy): Deno Deploy prohibits plainDeno.connectto port 443 (TLS termination is required on 443; see Deno’s “Pricing and limitations” page). The proxy pool only ever connects to proxy servers — typically on ports 80/1080/3128/8080 — so normal HTTP/SOCKS proxies are unaffected. Plain SOCKS/HTTP proxies on 443 would fail on Deploy but work under localdeno run. The/healthendpoint reports the effective mode underproxy.mode(direct,outbound, orpool). Tip for Multiple Cookies: You can rotate between multiple Google accounts by separating cookies with a pipe character (|), e.g.cookie_account_1| cookie_account_2.
Verification
Once deployed, check your health endpoint in your browser or with curl:poolSupported is true on Deno (raw TCP sockets are available), so setting ENABLE_PROXY=true switches the mode to pool — the same full proxy-pool experience as Cloudflare Workers.
Client Configuration
NextChat / ChatGPT-Next-Web
Cherry Studio / ChatBox
curl Test
Local Development
Run the exact same adapter locally with the Deno CLI (no account needed):http://localhost:8000 (Deno.serve’s default port; set the DENO_PORT environment variable, e.g. DENO_PORT=8081 deno run ..., to change it).
Always pass--allow-env: the adapter reads config from environment variables at request time. Running with only--allow-netmakes the first request block on Deno’s interactive permission prompt — in a background/pipe context that prompt is invisible and every request appears to hang forever. The entry now self-checks permissions at startup and exits with a clear message instead.
Troubleshooting
upstream timeout: no response within 50000ms (REQUEST_DEADLINE_MS) (502)
The server gave up waiting for Gemini because no upstream response (headers) arrived within REQUEST_DEADLINE_MS (default 50s). This is a symptom, not the root cause — on Deno Deploy the usual root causes are:
- Anonymous direct egress is throttled by Gemini. Requests without cookies leave from Deno Deploy’s shared edge IPs, which Gemini frequently hangs or stalls (especially for non-streaming requests, where the full response must be ready before any of it can be returned). Fixes, in order of effectiveness:
- Set a valid
COOKIE_STRING(+SAPISID) — the single most effective fix. - Enable the rotating proxy pool:
ENABLE_PROXY=true(Deno raw sockets are supported), or set a staticHTTPS_PROXY.
- Set a valid
- Long generations exceed the deadline. Non-streaming requests with big outputs can legitimately take >50s. Raise
REQUEST_DEADLINE_MS(e.g.90000), or usestream: trueso tokens arrive incrementally. - The 50s router deadline is shorter than the 55s retry budget. This is already fixed in code: the retry loop now aligns to the router deadline and surfaces the real per-attempt error (e.g. a readable per-attempt timeout with hints) instead of the generic 502. If you still see the generic message on an old deployment, redeploy.
ℹ️ SeeingHTTP 429: Too Many Requests - 请添加有效的 Cookie 或降低请求频率instead? That is the correct, attributed error — Gemini is answering with 429 (rate limited), and older versions could mask it behind the generic timeout when Gemini’sRetry-Afterwait exceeded the remaining deadline budget. The retry loop now surfaces the real 429 immediately instead of burning the budget on a doomed wait. If 429s are constant, setCOOKIE_STRINGor reduce request frequency. Quick check:GET /healthreports the effective outbound mode underproxy.mode(direct/outbound/pool) — if it saysdirectand you have no cookies, cause #1 applies to you.
Requests hang / no response at all (local deno run)
The adapter reads env config on every request. If you started the server without --allow-env (e.g. deno run --allow-net deno/deploy.js), the first request blocks on Deno’s interactive permission prompt. In a terminal you’d see the prompt, but with background/piped output it is invisible — the server just never replies. Start with both flags (the entry now exits immediately with a clear error when permissions are missing):
TLS proxying is not allowed / connection errors to port 443
Deno Deploy prohibits non-TLS Deno.connect to port 443. The proxy pool connects to proxy servers (rarely on 443), so this usually only bites if you add a SOCKS/HTTP proxy listening on 443 to STATIC_PROXIES. Move the proxy to a standard port, or drop ENABLE_PROXY and set HTTPS_PROXY instead (Deno fetch() tunnels through it natively).
Warmup/build fails with a timeout
Make sure the Entrypoint is set todeno/deploy.js and Runtime mode is Dynamic. The entry uses Deno.serve(); older Deploy Classic snippets that import serve() from deno.land/std/http will not work on the new platform.
Upstream 429 / empty responses
Gemini’s web endpoint rate-limits anonymous requests aggressively. Add a validCOOKIE_STRING (+ SAPISID) environment variable, or lower request frequency. The adapter enables the proxy pool (ENABLE_PROXY=true) to rotate exit IPs, which helps when a single IP is throttled.
Logs
Runtime logs, traces and metrics are available in the Deno Deploy dashboard under Logs / Traces for your app. The handler logs requests as[HH:MM:SS] [LEVEL] message when logRequests is enabled (default).