Gemini Web2API - Vercel Deployment Documentation
中文文档 | Cloudflare Docs | Netlify Docs | Deno Docs Run Gemini Web2API on Vercel Edge Functions for SSE streaming — zero config, no server to maintain.The endpoint lives atapi/gemini.js, a thin Vercel adapter over the shared core insrc/(the same core used by the Cloudflare worker and the Netlify functions).vercel.jsonroutes every path (e.g./v1/chat/completions,/health) to this single function via rewrites, and theexport const config = { runtime: 'edge' }at the bottom of the file runs it on the Edge runtime. Whyvercel.json+public/? This repo is API-only (no static frontend). Vercel’s “Other” framework preset expects an output directory namedpublic/— without it the build fails withNo Output Directory named "public" found. The emptypublic/.gitkeepsatisfies that, and the rewrite rules make the function reachable at the same paths as the Netlify/Cloudflare deployments.
⚡ Quick Deploy
Option 1: 1-Click Deploy to Vercel
- Click the Deploy button above.
- Connect your GitHub account and choose a repository name.
- (Optional) In Environment Variables, configure
API_KEYorCOOKIE_STRING. - Click Deploy. Your API is live at
https://your-app-name.vercel.app.
Option 2: Connect via Vercel Dashboard (Git)
- Fork or push this repository to your GitHub account.
- Open the Vercel Dashboard.
- Click Add New… → Project and import your repository.
- In Configure Project:
- Framework Preset:
Other - Build Command: (leave empty)
- Output Directory: (leave empty)
- Install Command: (leave empty)
- Framework Preset:
- Click Deploy. The repo’s
vercel.jsonsets the output directory (public/) and rewrites all paths toapi/gemini— no build settings needed.
Option 3: Vercel CLI
⚙️ Environment Variables (Optional)
Configure these in Vercel: Project Settings → Environment Variables (orvercel env add).
Proxy support on Vercel: Vercel Edge Functions do not provide raw TCP sockets (cloudflare:sockets), so the rotating proxy pool (ENABLE_PROXY/PROXY_ENABLED) is not supported on Vercel and is ignored with aWARNin the logs. Unlike Netlify Edge (Deno-based, nativeHTTPS_PROXYtunneling), Vercel’s Edge runtime does not auto-tunnelfetch()throughHTTPS_PROXYeither — direct connection is the only outbound mode on Vercel. If you need a proxy, use the Cloudflare Workers deployment. The/healthendpoint reports the effective mode underproxy.mode(directon Vercel).
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.
Platform Limits (Edge Runtime)
Verification
Once deployed, check your health endpoint in your browser or with curl:poolSupported is always false and proxy.mode is always direct — the platform offers no TCP sockets and no automatic proxy tunneling.
Client Configuration
NextChat / ChatGPT-Next-Web
Cherry Studio / ChatBox
curl Test
🛠️ Local Development
You can run and test the Vercel Edge Function locally using the Vercel CLI:http://localhost:3000, with the same rewrite routing as production. (The CLI requires a free Vercel account even for local dev.)
Troubleshooting
No Output Directory named "public" found after the Build completed
This repo ships a vercel.json with "outputDirectory": "public" and a public/.gitkeep
placeholder, so this should not happen on a fresh deploy. If you hit it anyway:
- Make sure
vercel.jsonandpublic/.gitkeepare committed and pushed. - Or set Output Directory to
publicunder Project Settings → Build & Output Settings.
FUNCTION_INVOCATION_TIMEOUT (504)
Vercel Edge Functions must begin sending a response within 25 seconds, otherwise the
invocation is terminated with a 504. Non-streaming requests now cap all retries at a 22s
pre-response deadline. If you still see this:
FUNCTION_INVOCATION_FAILED (500)
The function crashed with an unhandled exception. The handler has a top-level try/catch
that returns a structured JSON 500, so this usually means the error happened before the
handler was invoked. Check Deployments → Runtime Logs in the Vercel dashboard.
Malformed request (non-string model, non-object JSON body)
Fixed: invalid input returns a structured 400 instead of crashing.
Logs
Runtime logs are available in the Vercel dashboard under Deployments → Runtime Logs (orvercel logs <deployment-url>). The handler logs requests as
[HH:MM:SS] [LEVEL] message when logRequests is enabled (default).