← Back to Home

gemini-web2api — Turn Google Gemini's Web UI Into a Free OpenAI-Compatible API

gemini-web2api — Turn Google Gemini's Web UI Into a Free OpenAI-Compatible API

Google Gemini's web interface is powerful — it offers flash-thinking models, long context windows, and built-in web search — all free of charge. But it's stuck in a browser. You can't call it from your code, hook it up to an AI client like Cherry Studio or Open Interpreter, or use it with the OpenAI SDK.

gemini-web2api changes that. It's a single Python file that reverse-engineers Gemini's internal StreamGenerate protocol and exposes it as a standard /v1/chat/completions endpoint. Drop it behind any OpenAI-compatible client and you get Gemini's latest models through a familiar API — with tool calling, streaming, and configurable thinking depth.

Why It's Trending

In late May 2026, Sophomoresty/gemini-web2api surged to over 1,400 GitHub stars in its first week. The appeal is immediate:

  • Zero API cost — uses Gemini's free web access, not the paid API
  • OpenAI drop-in — no code changes needed for existing OpenAI SDK clients
  • Single file — one Python script, one optional dependency (httpx)
  • Gemini's best models — Flash, Flash Thinking (20k+ char output), and Pro
  • Tool/function calling — full OpenAI-format tool support through Gemini

As AI coding assistants proliferate (Claude Code, Codex, Gemini CLI, OpenCode), the need for a free, local-first API backend has never been greater. gemini-web2api fills that gap.

Architecture Overview

Here's how gemini-web2api bridges your tools to Google Gemini's web backend:

Architecture

On the left, any OpenAI-compatible client (Cherry Studio, Open Interpreter, your own app) sends standard API calls to the proxy. gemini-web2api translates those requests into Gemini's internal payload format and relays them to Google's StreamGenerate endpoint. The response is converted back to OpenAI format and streamed back via SSE. Optionally, a Gemini Advanced cookie can be provided for Pro model routing.

Prerequisites

  • A server or machine with Python 3.8+
  • Network access to gemini.google.com (a proxy/VPN may be needed in some regions)
  • Optionally: a Gemini Advanced account if you want Pro model access

Quick Start — 30 Seconds

pip install httpx
python gemini_web2api.py

That's it. The server starts at http://localhost:8081/v1 and is immediately usable.

Configuration

Create a config.json in the same directory as the script:

{
  "port": 8081,
  "host": "0.0.0.0",
  "api_keys": [],
  "cookie_file": null,
  "proxy": null,
  "log_requests": true
}

When api_keys is empty, authentication is disabled. To secure the server, add one or more API keys:

{
  "api_keys": ["sk-my-secret-key"]
}

Then all requests must include Authorization: Bearer <your-api-key>.

Using With Any OpenAI Client

curl

curl http://localhost:8081/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gemini-3.5-flash","messages":[{"role":"user","content":"Hello!"}]}'

OpenAI Python SDK

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8081/v1",
    api_key="sk-your-key"
)

response = client.chat.completions.create(
    model="gemini-3.5-flash-thinking",
    messages=[{"role": "user", "content": "Explain quantum computing in 3 sentences"}]
)
print(response.choices[0].message.content)

Cherry Studio / ChatBox

Field Value
Base URL http://localhost:8081/v1
API Key any key from config.json
Model gemini-3.5-flash-thinking

Gemini CLI

export GEMINI_API_KEY=sk-your-key
export GOOGLE_GEMINI_BASE_URL=http://localhost:8081
gemini

Available Models

  • gemini-3.5-flash — Fast, general-purpose (~12k chars output)
  • gemini-3.5-flash-thinking — Deep reasoning, longest output (~20k chars)
  • gemini-3.5-flash-thinking-lite — Adaptive thinking depth (~15k chars)
  • gemini-3.1-pro — Pro model (requires Gemini Advanced cookie for real routing)
  • gemini-auto — Auto model selection
  • gemini-flash-lite — Lightweight, fastest

Thinking Depth Control

Append @think=N to any model name to control thinking depth:

Suffix Depth
@think=0 Deepest (default)
@think=2 Medium
@think=4 Shallowest

Docker Deployment

cp config.example.json config.json
docker build -t gemini-web2api .
docker run -d --name gemini-web2api \
  -p 8081:8081 \
  -v ./config.json:/app/config.json \
  gemini-web2api

Or with Docker Compose:

version: "3"
services:
  gemini-web2api:
    build: .
    ports:
      - "8081:8081"
    volumes:
      - ./config.json:/app/config.json

Setting Up Pro Access (Optional)

Anonymous access works for all Flash models. For true Pro routing, you need a Gemini Advanced subscription and a browser cookie:

  1. Log into gemini.google.com with your paid account
  2. Export the cookies as a Netscape-format file
  3. Pass them to the server:
python gemini_web2api.py --cookie-file cookie.txt

Set "cookie_file": "/app/cookie.txt" in config.json for Docker deployments.

Tool/Function Calling

gemini-web2api supports OpenAI-format tool calling:

response = client.chat.completions.create(
    model="gemini-3.5-flash",
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get weather for a city",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string"}
                },
                "required": ["city"]
            }
        }
    }]
)

How It Works

gemini-web2api reverse-engineers Google Gemini's web StreamGenerate protocol. When you send an OpenAI-format request, the proxy:

  1. Extracts the model, messages, and tools from your request
  2. Constructs the internal Gemini payload — mapping your model choice to Gemini's MODE_CATEGORY enum (field [79])
  3. Sends it to the same StreamGenerate endpoint that powers the Gemini web app
  4. Parses the streaming response and converts it back to OpenAI's chat completion format

The result is a transparent bridge that requires no Gemini API key — only network access to gemini.google.com.

Limitations

  • No image input — Gemini's image upload uses a proprietary streaming RPC protocol (WIZ/ProcessFile) that can't be replicated in a standard HTTP proxy
  • Single-turn per request — multi-turn context is simulated by including previous messages in the prompt
  • Rate limits — Google may throttle high-frequency requests; the server retries automatically but sustained heavy use may be blocked
  • No real Pro without a paid cookie — without a Gemini Advanced subscription cookie, the Pro label falls back to Flash

Verification Checklist

Before deploying, run these checks:

  • Server starts: python gemini_web2api.py and it binds to port 8081
  • Basic request works: curl http://localhost:8081/v1/chat/completions -d '{"model":"gemini-3.5-flash","messages":[{"role":"user","content":"Say hello"}]}' returns a 200 with choices
  • Streaming works via the OpenAI SDK with stream=True
  • Tool calling works with the function calling example above
  • Configurable API keys are enforced when api_keys is non-empty

Resources

← Retour à l'Accueil

gemini-web2api — Transformez l'interface Web de Google Gemini en une API compatible OpenAI gratuite

gemini-web2api — Transformez l'interface Web de Google Gemini en une API compatible OpenAI gratuite

L'interface web de Google Gemini est puissante — elle propose des modèles flash-thinking, de longs contextes et une recherche web intégrée, le tout gratuitement. Mais elle reste confinée dans un navigateur. Vous ne pouvez pas l'appeler depuis votre code, la connecter à un client IA comme Cherry Studio ou Open Interpreter, ni l'utiliser avec le SDK OpenAI.

gemini-web2api change cela. C'est un seul fichier Python qui rétro-ingénérie le protocole interne StreamGenerate de Gemini et l'expose comme un endpoint standard /v1/chat/completions. Placez-le derrière n'importe quel client compatible OpenAI et vous obtenez les derniers modèles Gemini via une API familière — avec appel d'outils, streaming et profondeur de pensée configurable.

Pourquoi il fait le buzz

Fin mai 2026, Sophomoresty/gemini-web2api a dépassé les 1 400 étoiles GitHub en une semaine. L'attrait est immédiat :

  • Coût API zéro — utilise l'accès web gratuit de Gemini, pas l'API payante
  • Remplacement direct OpenAI — aucun changement de code nécessaire pour les clients SDK OpenAI existants
  • Fichier unique — un script Python, une dépendance optionnelle (httpx)
  • Meilleurs modèles Gemini — Flash, Flash Thinking (20k+ caractères), et Pro
  • Appel d'outils/fonctions — support complet des outils au format OpenAI via Gemini

Avec la prolifération des assistants de codage IA (Claude Code, Codex, Gemini CLI, OpenCode), le besoin d'un backend API local et gratuit n'a jamais été aussi grand. gemini-web2api comble ce vide.

Architecture

Voici comment gemini-web2api fait le pont entre vos outils et le backend web de Google Gemini :

Architecture

À gauche, n'importe quel client compatible OpenAI (Cherry Studio, Open Interpreter, votre propre application) envoie des appels API standard au proxy. gemini-web2api traduit ces requêtes au format interne de Gemini et les relaie vers l'endpoint StreamGenerate de Google. La réponse est reconvertie au format OpenAI et renvoyée via SSE. Optionnellement, un cookie Gemini Advanced peut être fourni pour le routage vers le modèle Pro.

Prérequis

  • Un serveur ou une machine avec Python 3.8+
  • Accès réseau à gemini.google.com (un proxy/VPN peut être nécessaire dans certaines régions)
  • Optionnellement : un compte Gemini Advanced pour l'accès au modèle Pro

Démarrage rapide — 30 secondes

pip install httpx
python gemini_web2api.py

C'est tout. Le serveur démarre sur http://localhost:8081/v1 et est immédiatement utilisable.

Configuration

Créez un fichier config.json dans le même répertoire :

{
  "port": 8081,
  "host": "0.0.0.0",
  "api_keys": [],
  "cookie_file": null,
  "proxy": null,
  "log_requests": true
}

Quand api_keys est vide, l'authentification est désactivée. Pour sécuriser le serveur, ajoutez une ou plusieurs clés API :

{
  "api_keys": ["***"]
}

Toutes les requêtes devront alors inclure `Authorization: Bearer *** Using With Any OpenAI Client

curl

curl http://localhost:8081/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gemini-3.5-flash","messages":[{"role":"user","content":"Bonjour!"}]}'

SDK Python OpenAI

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8081/v1",
    api_key="sk-your-key"
)

response = client.chat.completions.create(
    model="gemini-3.5-flash-thinking",
    messages=[{"role": "user", "content": "Explique la mécanique quantique en 3 phrases"}]
)
print(response.choices[0].message.content)

Cherry Studio / ChatBox

Champ Valeur
URL de base http://localhost:8081/v1
Clé API n'importe quelle clé du config.json
Modèle gemini-3.5-flash-thinking

Gemini CLI

export GEMINI_API_KEY=sk-you...ort GOOGLE_GEMINI_BASE_URL=http://localhost:8081
gemini

Modèles disponibles

  • gemini-3.5-flash — Rapide, usage général (~12k caractères)
  • gemini-3.5-flash-thinking — Raisonnement profond, sortie la plus longue (~20k caractères)
  • gemini-3.5-flash-thinking-lite — Profondeur de pensée adaptative (~15k caractères)
  • gemini-3.1-pro — Modèle Pro (nécessite un cookie Gemini Advanced)
  • gemini-auto — Sélection automatique du modèle
  • gemini-flash-lite — Léger et très rapide

Contrôle de la profondeur de pensée

Ajoutez @think=N à tout nom de modèle :

Suffixe Profondeur
@think=0 Maximale (défaut)
@think=2 Moyenne
@think=4 Minimale

Déploiement Docker

cp config.example.json config.json
docker build -t gemini-web2api .
docker run -d --name gemini-web2api \
  -p 8081:8081 \
  -v ./config.json:/app/config.json \
  gemini-web2api

Ou avec Docker Compose :

version: "3"
services:
  gemini-web2api:
    build: .
    ports:
      - "8081:8081"
    volumes:
      - ./config.json:/app/config.json

Accès Pro (optionnel)

L'accès anonyme fonctionne pour tous les modèles Flash. Pour le vrai routage Pro, vous avez besoin d'un abonnement Gemini Advanced et d'un cookie de navigateur :

  1. Connectez-vous à gemini.google.com avec votre compte payant
  2. Exportez les cookies au format Netscape
  3. Passez-les au serveur :
python gemini_web2api.py --cookie-file cookie.txt

Définissez "cookie_file": "/app/cookie.txt" dans config.json pour les déploiements Docker.

Appel d'outils / fonctions

gemini-web2api supporte les appels d'outils au format OpenAI :

response = client.chat.completions.create(
    model="gemini-3.5-flash",
    messages=[{"role": "user", "content": "Quel temps fait-il à Paris ?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Obtenir la météo d'une ville",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string"}
                },
                "required": ["city"]
            }
        }
    }]
)

Comment ça marche

gemini-web2api rétro-ingénérie le protocole StreamGenerate web de Google Gemini. Quand vous envoyez une requête au format OpenAI, le proxy :

  1. Extrait le modèle, les messages et les outils de votre requête
  2. Construit la charge utile interne de Gemini — en mappant votre choix de modèle à l'énumération MODE_CATEGORY de Gemini (champ [79])
  3. L'envoie au même endpoint StreamGenerate qui alimente l'application web Gemini
  4. Analyse la réponse en streaming et la reconvertit au format chat completion d'OpenAI

Le résultat est un pont transparent qui ne nécessite aucune clé API Gemini — seulement un accès réseau à gemini.google.com.

Limitations

  • Pas d'image — L'upload d'images dans Gemini utilise un protocole RPC propriétaire (WIZ/ProcessFile) qui ne peut pas être reproduit dans un proxy HTTP standard
  • Un seul tour par requête — Le contexte multi-tour est simulé en incluant les messages précédents dans le prompt
  • Limites de débit — Google peut limiter les requêtes à haute fréquence ; le serveur réessaie automatiquement
  • Pas de vrai Pro sans cookie payant — Sans cookie d'abonnement Gemini Advanced, le modèle Pro se rabat sur Flash

Liste de vérification

Avant de déployer, vérifiez ces points :

  • Le serveur démarre : python gemini_web2api.py et écoute sur le port 8081
  • Requête de base : curl http://localhost:8081/v1/chat/completions -d '{"model":"gemini-3.5-flash","messages":[{"role":"user","content":"Dis bonjour"}]}' retourne un 200 avec des choix
  • Le streaming fonctionne via le SDK OpenAI avec stream=True
  • L'appel d'outils fonctionne avec l'exemple de fonction ci-dessus
  • Les clés API configurables sont appliquées quand api_keys est non vide

Ressources