Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

Gemini Logo

Release Go Version Docker GHCR License Maintained

Stars Issues PRs Welcome

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. 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 and sign in
  2. Press F12ApplicationStorageCookies
  3. Copy the values of __Secure-1PSID and __Secure-1PSIDTS

Step 2 — Run

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 GEMINI_TEMPORARY=false \
  -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. 🎉


🛠️ 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

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 and sign in

  2. Press F12ApplicationStorageCookies

  3. Copy the values of __Secure-1PSID and __Secure-1PSIDTS

  4. Create your .env from the example:

    cp .env.example .env
  5. Paste your cookie values into .env:

    GEMINI_1PSID=your_psid_here
    GEMINI_1PSIDTS=your_psidts_here
    GEMINI_REFRESH_INTERVAL=30
    GEMINI_MAX_RETRIES=3
    GEMINI_TEMPORARY=false
    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:

MethodCommandRequirements
🐳 Docker Composedocker compose up -d --buildDocker
🐹 Go directgo run cmd/server/main.goGo 1.21+
⚡ Task (dev mode)task devTask

Done! Jump to Test it. 🎉


✅ Test it

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, Scalar UI, health checks
  • 📝 Well Documented: Interactive API docs at /docs
  • 🖼️ Image Generation: OpenAI-compatible text-to-image with authenticated b64_json output
  • 🧩 Image Inputs: Remote URLs, data: URLs and multiple reference images in chat requests

See Image generation and image inputs for tested examples, limitations and security guidance.


🛠️ Configuration

Environment Variables

VariableRequiredDefaultDescription
GEMINI_1PSID✅ YesMain session cookie from Gemini
GEMINI_1PSIDTS✅ YesTimestamp cookie (prevents auth errors)
GEMINI_REFRESH_INTERVAL❌ No30Cookie rotation interval (minutes)
GEMINI_MAX_RETRIES❌ No3Max retry attempts when an API call fails
GEMINI_TEMPORARY❌ NofalseEnable stateless/incognito mode for all requests
PORT❌ No4981Server port
RATE_LIMIT_ENABLED❌ NofalseEnable or disable rate limiting
RATE_LIMIT_WINDOW_MS❌ No60000Rate limit time window in milliseconds
RATE_LIMIT_MAX_REQUESTS❌ No10Maximum 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)

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)

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)

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

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/ directory.


📘 API Documentation

Once running, visit http://localhost:4981/docs for interactive API documentation powered by Scalar.

Scalar UI


🤝 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 file for details.


⭐ Star History

If you find this project useful, please consider giving it a star! ⭐


🔗 Links


Made with ❤️ by the Gemini Web To API team

关于 About

✨Reverse-engineered API for Gemini web app. It can be used as a genuine API key from OpenAI, Gemini, and Claude.
aiapichatbotclaudedockerfiber-frameworkgeminigemini-apigenerative-aigooglellmopenaiproxy-serverrest-apireverse-proxy

语言 Languages

Go99.7%
Dockerfile0.3%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
92
Total Commits
峰值: 32次/周
Less
More

核心贡献者 Contributors