Skip to main content

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 at api/gemini.js, a thin Vercel adapter over the shared core in src/ (the same core used by the Cloudflare worker and the Netlify functions). vercel.json routes every path (e.g. /v1/chat/completions, /health) to this single function via rewrites, and the export const config = { runtime: 'edge' } at the bottom of the file runs it on the Edge runtime. Why vercel.json + public/? This repo is API-only (no static frontend). Vercel’s “Other” framework preset expects an output directory named public/ — without it the build fails with No Output Directory named "public" found. The empty public/.gitkeep satisfies 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

Deploy with Vercel
  1. Click the Deploy button above.
  2. Connect your GitHub account and choose a repository name.
  3. (Optional) In Environment Variables, configure API_KEY or COOKIE_STRING.
  4. Click Deploy. Your API is live at https://your-app-name.vercel.app.

Option 2: Connect via Vercel Dashboard (Git)

  1. Fork or push this repository to your GitHub account.
  2. Open the Vercel Dashboard.
  3. Click Add New…Project and import your repository.
  4. In Configure Project:
    • Framework Preset: Other
    • Build Command: (leave empty)
    • Output Directory: (leave empty)
    • Install Command: (leave empty)
  5. Click Deploy. The repo’s vercel.json sets the output directory (public/) and rewrites all paths to api/gemini — no build settings needed.

Option 3: Vercel CLI


⚙️ Environment Variables (Optional)

Configure these in Vercel: Project SettingsEnvironment Variables (or vercel 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 a WARN in the logs. Unlike Netlify Edge (Deno-based, native HTTPS_PROXY tunneling), Vercel’s Edge runtime does not auto-tunnel fetch() through HTTPS_PROXY either — direct connection is the only outbound mode on Vercel. If you need a proxy, use the Cloudflare Workers deployment. The /health endpoint reports the effective mode under proxy.mode (direct on 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:
Expected response:
On Vercel, 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:
The local server will start at 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.json and public/.gitkeep are committed and pushed.
  • Or set Output Directory to public under 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 (or vercel logs <deployment-url>). The handler logs requests as [HH:MM:SS] [LEVEL] message when logRequests is enabled (default).