# sophomoresty/gemini-web2api architecture

> Architecture diagram of the GitHub repository sophomoresty/gemini-web2api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sophomoresty/gemini-web2api
- Repository: https://github.com/sophomoresty/gemini-web2api

## Overview

gemini-web2api turns Gemini Web into compatible APIs. The main workflow is client request → endpoint translation and model selection → prompt/tool and image preparation → Gemini Web generation → compatible response. Separate documented capabilities include OpenAI Chat Completions, Responses API, Google Gemini-native endpoints, streaming, tool calling, model/thinking options, and optional cookie-based Pro access. The graph also shows the cookie-export extension and standalone Cloudflare Worker; their connections to the Python server are not assumed. Arrows reflect README statements or shown source calls; unsampled implementation details are omitted.

Main entry points: [`gemini_web2api/server.py`](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py) (Chat Completions), [`gemini_web2api/gemini.py`](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/gemini.py) (Gemini generation), [`gemini_web2api/multimodal.py`](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/multimodal.py) (Image upload), [`gemini_web2api/models.py`](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/models.py) (Model mapping)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API surface"]
  node_entry["Server startup<br/>[__main__.py]"]
  node_http["HTTP endpoints<br/>[server.py]"]
  node_chat["Chat Completions<br/>[server.py]"]
  node_responses["Responses API<br/>[server.py]"]
  node_googleapi["Gemini native API<br/>[server.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_translation["Request translation"]
  node_models["Model mapping<br/>[models.py]"]
  node_prompt["Prompt and tools<br/>[tools.py]"]
  node_images["Image parsing<br/>[tools.py]"]
end

subgraph group_upstream["Gemini integration"]
  node_upload["Image upload<br/>[multimodal.py]"]
  node_generation["Gemini generation<br/>[gemini.py]"]
end

subgraph group_access["Access and deployment"]
  node_cookieext["Cookie sync extension<br/>[popup.js]"]
  node_worker["Cloudflare Worker<br/>[worker.js]"]
end

node_client(("API client"))
node_gemini(("Gemini Web"))

node_client -->|"sends requests"| node_http
node_entry -->|"loads settings"| node_config
node_entry -->|"starts server"| node_http
node_http -->|"routes requests"| node_chat
node_http -->|"routes requests"| node_responses
node_http -->|"routes requests"| node_googleapi
node_chat -->|"resolves model"| node_models
node_responses -->|"resolves model"| node_models
node_googleapi -->|"resolves model"| node_models
node_chat -->|"builds prompt"| node_prompt
node_chat -->|"parses images"| node_images
node_googleapi -->|"builds prompt"| node_prompt
node_googleapi -->|"uploads images"| node_upload
node_chat -->|"uploads images"| node_upload
node_chat -->|"requests generation"| node_generation
node_responses -->|"requests generation"| node_generation
node_googleapi -->|"requests generation"| node_generation
node_generation -->|"sends web request"| node_gemini
node_upload -->|"uploads image"| node_gemini
node_cookieext -.->|"exports cookie settings"| node_config
node_client -.->|"calls API"| node_worker

click node_entry "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/__main__.py"
click node_http "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py"
click node_chat "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py"
click node_responses "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py"
click node_googleapi "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py"
click node_config "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/config.py"
click node_models "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/models.py"
click node_prompt "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/tools.py"
click node_images "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/tools.py"
click node_upload "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/multimodal.py"
click node_generation "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/gemini.py"
click node_cookieext "https://github.com/sophomoresty/gemini-web2api/blob/main/gemini-cookie-sync-extension/popup.js"
click node_worker "https://github.com/sophomoresty/gemini-web2api/blob/main/cloudflare/worker.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_http,node_chat,node_responses,node_googleapi,node_config,node_client toneBlue
class node_models,node_prompt,node_images toneAmber
class node_upload,node_generation toneMint
class node_cookieext,node_worker toneRose
class node_gemini toneIndigo
```

## Components

### API surface

- [Server startup](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/__main__.py): `gemini_web2api/__main__.py`
- [HTTP endpoints](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py): `gemini_web2api/server.py`
- [Chat Completions](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py): `gemini_web2api/server.py`
- [Responses API](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py): `gemini_web2api/server.py`
- [Gemini native API](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/server.py): `gemini_web2api/server.py`
- [Runtime configuration](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/config.py): `gemini_web2api/config.py`

### Request translation

- [Model mapping](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/models.py): `gemini_web2api/models.py`
- [Prompt and tools](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/tools.py): `gemini_web2api/tools.py`
- [Image parsing](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/tools.py): `gemini_web2api/tools.py`

### Gemini integration

- [Image upload](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/multimodal.py): `gemini_web2api/multimodal.py`
- [Gemini generation](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini_web2api/gemini.py): `gemini_web2api/gemini.py`

### Access and deployment

- [Cookie sync extension](https://github.com/sophomoresty/gemini-web2api/blob/main/gemini-cookie-sync-extension/popup.js): `gemini-cookie-sync-extension/popup.js`
- [Cloudflare Worker](https://github.com/sophomoresty/gemini-web2api/blob/main/cloudflare/worker.js): `cloudflare/worker.js`

### Other components

- **API client**
- **Gemini Web**

## Connections

- API client → HTTP endpoints: sends requests (evidence: `README.md`)
- Server startup → Runtime configuration: loads settings (evidence: `gemini_web2api/__main__.py`)
- Server startup → HTTP endpoints: starts server (evidence: `gemini_web2api/__main__.py`)
- HTTP endpoints → Chat Completions: routes requests (evidence: `README.md`)
- HTTP endpoints → Responses API: routes requests (evidence: `README.md`)
- HTTP endpoints → Gemini native API: routes requests (evidence: `README.md`)
- Chat Completions → Model mapping: resolves model (evidence: `gemini_web2api/server.py`)
- Responses API → Model mapping: resolves model (evidence: `gemini_web2api/server.py`)
- Gemini native API → Model mapping: resolves model (evidence: `gemini_web2api/server.py`)
- Chat Completions → Prompt and tools: builds prompt (evidence: `gemini_web2api/server.py`)
- Chat Completions → Image parsing: parses images (evidence: `gemini_web2api/server.py`)
- Gemini native API → Prompt and tools: builds prompt (evidence: `gemini_web2api/server.py`)
- Gemini native API → Image upload: uploads images (evidence: `gemini_web2api/server.py`)
- Chat Completions → Image upload: uploads images (evidence: `gemini_web2api/server.py`)
- Chat Completions → Gemini generation: requests generation (evidence: `gemini_web2api/server.py`)
- Responses API → Gemini generation: requests generation (evidence: `README.md`)
- Gemini native API → Gemini generation: requests generation (evidence: `gemini_web2api/server.py`)
- Gemini generation → Gemini Web: sends web request (evidence: `gemini_web2api/gemini.py`)
- Image upload → Gemini Web: uploads image (evidence: `gemini_web2api/multimodal.py`)
- Cookie sync extension → Runtime configuration: exports cookie settings (evidence: `README.md`)
- API client → Cloudflare Worker: calls API
