zhiyu1998/Gemi2Api-Server

HanaokaYuzu / Gemini-API 的服务端简单实现,仓库自动更新上游,支持gemini-3.8-flash、gemini-3.5-flash-lite 等

Gemi2Api‑Server – a thin wrapper that turns Google Gemini’s web UI into an OpenAI‑compatible API

What it is

  • A small FastAPI service that logs into Google Gemini using the cookies you export from a normal browser session (__Secure-1PSID and __Secure-1PSIDTS).
  • It then forwards chat‑completion requests to Gemini’s private web API and returns the response in the same shape as the OpenAI /v1/chat/completions endpoint.
  • An optional admin panel (/admin) lets you view the connection status, edit the cookies, change the API key used for authentication, and test the model live.

Why it exists

  • Google does not provide a public, paid Gemini endpoint (as of the README’s writing). This project offers a self‑hosted bridge so you can call Gemini from tools that expect an OpenAI‑style REST API.
  • It also lets you add custom model definitions (via a YAML file) and expose them through the /v1/models list.

How to get it running

  1. Obtain Gemini cookies – log into https://gemini.google.com in an incognito window, open the dev‑tools, and copy the values of __Secure-1PSID and __Secure-1PSIDTS.
  2. Create a .env file (copy from .env.example) and paste the two cookie values, plus an API_KEY you’ll use to protect the admin UI.
  3. Deploy – you can:
    • Run locally with uvicorn main:app --reload after installing the Python deps (fastapi, uvicorn, gemini-webapi, httpx, h2).
    • Use the provided Docker‑Compose setup (docker-compose up -d).
    • Click the one‑click “Deploy to Render” or “Duplicate on HuggingFace” badges for a hosted instance.
  4. Optional custom models – add a custom_models.yaml that maps a friendly name (e.g., gemini-3.5-flash) to the raw x-goog-ext-… header values required by Gemini’s internal API. The file is hot‑reloaded, so you can edit it without restarting.

Key configuration knobs

Variable Purpose
SECURE_1PSID / SECURE_1PSIDTS Authentication cookies for Gemini (mandatory).
API_KEY Simple token required to access /admin and to protect the public API.
TEMPORARY_CHAT When true the server uses Gemini’s “temporary conversation” mode, which disables features like image generation and chain‑of‑thought reasoning.
AUTO_DELETE_CHAT If true, the server tells Gemini to delete the conversation after the response, keeping the web account clean.
PUBLIC_BASE_URL Base URL used when the server proxies generated images; needed if you run behind a reverse proxy.
CUSTOM_MODELS_FILE Path to a YAML/JSON file that adds or overrides model definitions.
DISABLE_BUILTIN_MODELS If set, only the models listed in CUSTOM_MODELS_FILE are advertised via /v1/models.

What you can do with the API

  • GET /v1/models – returns a list of model IDs that the server knows about.
  • POST /v1/chat/completions – send a JSON payload identical to OpenAI’s chat API; the server forwards it to Gemini and streams back the reply.
  • GET /gemini-proxy/image – a tiny image‑proxy endpoint used when Gemini returns a generated image URL; it rewrites the URL so the image can be fetched from the server’s host.
  • GET /admin – a web UI for monitoring health, editing cookies, and testing chats.

Who might use it

  • Developers who want to experiment with Gemini in notebooks, LangChain, or other frameworks that already support OpenAI‑style endpoints.
  • Small teams that need a quick, self‑hosted bridge without paying for a commercial Gemini API (if/when one becomes available).
  • Hobbyists who want to run a personal “Gemini‑as‑a‑service” instance on Render, HuggingFace Spaces, or their own VPS.

Limitations & caveats

  • It relies on undocumented internal Gemini web APIs; Google can change the cookie format or request headers at any time, which will break the bridge.
  • The service needs a valid, non‑expired Gemini login; frequent 500 errors usually mean the cookies have expired or the IP is blocked.
  • Security is minimal – the only protection is the API_KEY you set. Treat the server as a trusted internal component, not a public internet‑facing service.

Where to find more

  • The original upstream project is HanaokaYuzu / Gemini‑API; Gemi2Api‑Server is a lightweight server wrapper around that library.
  • Issues and troubleshooting tips are linked in the README (e.g., handling 500 errors).

All details above are taken directly from the repository’s README; no external speculation has been added.

Related

  • Project
  • Project
  • Project
  • Project
  • Project