https://github.com/ntthanh2603/gemini-web-to-api
β¨Reverse-engineered API for Gemini web app. It can be used as a genuine API key from OpenAI, Gemini, and Claude.
https://github.com/ntthanh2603/gemini-web-to-api
ai api chatbot claude docker fiber-framework gemini gemini-api generative-ai google llm openai proxy-server rest-api reverse-proxy
Last synced: about 2 months ago
JSON representation
β¨Reverse-engineered API for Gemini web app. It can be used as a genuine API key from OpenAI, Gemini, and Claude.
- Host: GitHub
- URL: https://github.com/ntthanh2603/gemini-web-to-api
- Owner: ntthanh2603
- License: mit
- Created: 2025-12-31T04:01:00.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2026-02-24T23:43:38.000Z (4 months ago)
- Last Synced: 2026-02-25T04:49:20.221Z (4 months ago)
- Topics: ai, api, chatbot, claude, docker, fiber-framework, gemini, gemini-api, generative-ai, google, llm, openai, proxy-server, rest-api, reverse-proxy
- Language: Go
- Homepage:
- Size: 80.6 MB
- Stars: 24
- Watchers: 1
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Gemini Web To API π
Transforms Google Gemini web interface into a standardized REST API.
Access Gemini's power without API keys β just use your cookies!
> [!NOTE]
> This project is intended for **research and educational purposes only**. Please use responsibly and refrain from any commercial use.
> [!WARNING]
> This project is not affiliated with Google. It uses reverse-engineered web cookies and may not comply with [Google's Terms of Service](https://policies.google.com/terms). Use at your own risk β the author assumes no responsibility for any account actions or data loss.
---
## π― Why Gemini Web To API?
**Problem**: You want to use Google Gemini's latest models, but you don't have an API key or prefer not to use one.
**Solution**: Creates a local API server that:
- β
Connects to Gemini's web interface using your browser cookies
- β
Exposes OpenAI / Claude / Gemini-compatible API endpoints
- β
No API keys needed β just cookies from your browser
- β
Handles authentication and session management automatically
**Use Cases**:
- Use Gemini without API keys
- Test Gemini integration locally
- Build applications leveraging Gemini's latest models
- Develop with cookie-based authentication
---
## β‘ Quick Start
### π³ Option A β Docker Run (no setup required)
> No cloning needed β pull and run directly from the registry.
**Step 1 β Get your cookies**
> [!WARNING]
> Keep these values secure and **never share or commit them** β they provide direct access to your Google account.
1. Go to [gemini.google.com](https://gemini.google.com) and sign in
2. Press `F12` β **Application** β **Storage** β **Cookies**
3. Copy the values of `__Secure-1PSID` and `__Secure-1PSIDTS`
**Step 2 β Run**
```bash
docker run -d -p 4981:4981 \
-e GEMINI_1PSID="your_psid_here" \
-e GEMINI_1PSIDTS="your_psidts_here" \
-e GEMINI_REFRESH_INTERVAL=30 \
-e GEMINI_MAX_RETRIES=3 \
-e APP_ENV=production \
-e RATE_LIMIT_ENABLED=true \
-e RATE_LIMIT_WINDOW_MS=60000 \
-e RATE_LIMIT_MAX_REQUESTS=10 \
-v ./cookies:/home/appuser/.cookies \
--tmpfs /tmp:rw,size=512m \
--tmpfs /home/appuser/.cache:rw,size=256m \
--name gemini-web-to-api \
--restart unless-stopped \
ghcr.io/ntthanh2603/gemini-web-to-api:latest
```
**Done!** Jump to [Test it](#-test-it). π
---
### π οΈ Option B β Build from source
> Use this if you want to build for a specific architecture (amd64, arm64, etc.) or modify the source code.
**Step 1 β Clone the repository**
```bash
git clone https://github.com/ntthanh2603/gemini-web-to-api.git
cd gemini-web-to-api
```
**Step 2 β Get your cookies and configure `.env`**
> [!WARNING]
> Keep these values secure and **never commit your `.env` file** β it contains credentials that provide access to your Google account.
1. Go to [gemini.google.com](https://gemini.google.com) and sign in
2. Press `F12` β **Application** β **Storage** β **Cookies**
3. Copy the values of `__Secure-1PSID` and `__Secure-1PSIDTS`
4. Create your `.env` from the example:
```bash
cp .env.example .env
```
5. Paste your cookie values into `.env`:
```env
GEMINI_1PSID=your_psid_here
GEMINI_1PSIDTS=your_psidts_here
GEMINI_REFRESH_INTERVAL=30
GEMINI_MAX_RETRIES=3
APP_ENV=production
RATE_LIMIT_ENABLED=true
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=10
```
**Step 3 β Run**
Pick whichever method suits your setup:
| Method | Command | Requirements |
|---|---|---|
| π³ Docker Compose | `docker compose up -d --build` | Docker |
| πΉ Go direct | `go run cmd/server/main.go` | [Go 1.21+](https://golang.org/dl/) |
| β‘ Task (dev mode) | `task dev` | [Task](https://taskfile.dev) |
**Done!** Jump to [Test it](#-test-it). π
---
### β
Test it
```bash
curl -X POST http://localhost:4981/openai/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "gemini-advanced", "messages": [{"role": "user", "content": "Hello!"}]}'
```
Your Gemini Web To API is running at `http://localhost:4981` π
---
## β¨ Features
- π **Universal AI Bridge**: One server, three protocols (OpenAI, Claude, Gemini)
- π **Drop-in Replacement**: Works with existing OpenAI / Claude / Gemini SDKs
- π **Smart Session Management**: Auto-rotates cookies to keep sessions alive
- β‘ **High Performance**: Built with Go and Fiber for speed
- π³ **Production Ready**: Docker Compose support, Swagger UI, health checks
- π **Well Documented**: Interactive API docs at `/swagger/`
---
## π οΈ Configuration
### Environment Variables
| Variable | Required | Default | Description |
| ------------------------- | -------- | ------- | ---------------------------------------------------- |
| `GEMINI_1PSID` | β
Yes | β | Main session cookie from Gemini |
| `GEMINI_1PSIDTS` | β
Yes | β | Timestamp cookie (prevents auth errors) |
| `GEMINI_REFRESH_INTERVAL` | β No | `30` | Cookie rotation interval (minutes) |
| `GEMINI_MAX_RETRIES` | β No | `3` | Max retry attempts when an API call fails |
| `PORT` | β No | `4981` | Server port |
| `RATE_LIMIT_ENABLED` | β No | `false` | Enable or disable rate limiting |
| `RATE_LIMIT_WINDOW_MS` | β No | `60000` | Rate limit time window in milliseconds |
| `RATE_LIMIT_MAX_REQUESTS` | β No | `10` | Maximum number of requests allowed per time window |
### Configuration Priority
1. **Environment Variables** (highest priority)
2. **`.env` file**
3. **Defaults** (lowest priority)
---
## π§ͺ Usage Examples
### OpenAI SDK (Python)
```python
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:4981/openai/v1",
api_key="not-needed"
)
response = client.chat.completions.create(
model="gemini-advanced",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
```
### Claude SDK (Python)
```python
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(
base_url="http://localhost:4981/claude",
model="gemini-advanced",
api_key="not-needed"
)
response = llm.invoke("Explain quantum computing")
print(response.content)
```
### Gemini Native SDK (Python)
```python
import google.generativeai as genai
genai.configure(
api_key="not-needed",
transport="rest",
client_options={"api_endpoint": "http://localhost:4981/gemini"}
)
model = genai.GenerativeModel("gemini-advanced")
response = model.generate_content("Write a poem about coding")
print(response.text)
```
### cURL
```bash
curl -X POST http://localhost:4981/openai/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-advanced",
"messages": [{"role": "user", "content": "What is AI?"}],
"stream": false
}'
```
More examples are available in the [`examples/`](examples/) directory.
---
## π API Documentation
Once running, visit **`http://localhost:4981/swagger/index.html`** for interactive API documentation.

---
## π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
---
## π License
This project is licensed under the MIT License β see the [LICENSE](LICENSE) file for details.
---
## β Star History
If you find this project useful, please consider giving it a star! β
---
## π Links
- **GitHub**: [ntthanh2603/gemini-web-to-api](https://github.com/ntthanh2603/gemini-web-to-api)
- **Gemini Web**: [gemini.google.com](https://gemini.google.com)
- **Issues**: [Report a bug](https://github.com/ntthanh2603/gemini-web-to-api/issues)
---
**Made with β€οΈ by the Gemini Web To API team**