DV

davidkk/vercel-gemini-proxy

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

16 stars 质量 85 趋势 41MIT

Gemini API proxy on Vercel Edge.

概览

is a Gemini API proxy on Vercel (Next.js App Router) for regions where direct Gemini access is slow or blocked, plus a browser streaming playground for debugging. gemini-relay-proxy.vercel.app/chat (demo only) - Prefer DNS in a region that can reach Google Gemini. Do not rely on *.vercel.app in production. If needed, front the service with a jump host or another edge proxy (e.g. CF). - Use Gemini API key. Do not share or reuse others’ keys. - Multiturn messages must end with role: user (or a function response). If the first message is not user, the proxy drops it; if the last is not user, the request is rejected. - Auth paths: /api/v1, /api/v1beta, /api/v1beta2 only. - ?key= or x-goog-api-key with your Gemini key. - headers from PROXY_AUTH_HEADERS; server injects a key from GEMINI_API_KEYS. - Missing credential/path → 401. Proxy mode without GEMINI_API_KEYS → 503. Empty JSON body on POST/PUT/PATCH → 403 (GET needs no body). - Runs on Next.

README

以下为原文 README 节选,完整内容请查看原文。

Gemini Relay

Gemini Relay is a Gemini API proxy on Vercel (Next.js App Router) for regions where direct Gemini access is slow or blocked, plus a browser streaming playground for debugging.

Try it: gemini-relay-proxy.vercel.app/chat (demo only)

Important notes

  • Custom domain required for production. Prefer DNS in a region that can reach Google Gemini. Do not rely on *.vercel.app in production. If needed, front the service with a jump host or another edge proxy (e.g. CF).
  • Use your own Gemini API key. Do not share or reuse others’ keys.
  • Multiturn messages must end with role: user (or a function response). If the first message is not user, the proxy drops it; if the last is not user, the request is rejected.
  • Auth paths: /api/v1, /api/v1beta, /api/v1beta2 only.
    • Passthrough: ?key= or x-goog-api-key with your Gemini key.
    • Proxy mode: headers from PROXY_AUTH_HEADERS; server injects a key from GEMINI_API_KEYS.
    • Missing credential/path → 401. Proxy mode without GEMINI_API_KEYS → 503. Empty JSON body on POST/PUT/PATCH → 403 (GET needs no body).
  • Runs on Next.js App Router Route Handlers (nodejs + Fluid Compute): app/api/v1|v1beta|v1beta2/[...path] → services/gemini/. Successful calls return 200 then stream. maxDuration and business timeout are 120s.
  • Model IDs live in the URL (transparent forward), e.g. /api/v1beta/models/{model}:generateContent. Prefer current Stable: gemini-3.5-flash (general) or gemini-3.5-flash-lite (lighter). Playground can Refresh the official model list.
  • Debug via Vercel → Logs (or local pnpm dev terminal). Playground / MCP are for debugging; generation still goes through the REST proxy.

Deploy

  1. Clone / import the repo and deploy.
  2. Attach a custom domain.
在 GitHub 查看完整 README

推荐工具

换一个关键词,或者移除筛选条件。

安装

npx skillfish add davidkk/vercel-gemini-proxy
新手?先看 mcpskill.org 教程 →