gm-2api / docs /README_EN.md
yu
Add Dockerfile and code
4bcd925

๏ปฟ

Gemini Business2API logo

Gemini Business2API

Empowering AI with seamless integration

็ฎ€ไฝ“ไธญๆ–‡ | English

๐Ÿ’ก Tip: Remote environments (Hugging Face/Linux) and local environments can share the same database for automatic account data synchronization

Convert Gemini Business to OpenAI-compatible API with multi-account load balancing, image generation, multimodal capabilities, and built-in admin panel.


๐Ÿ“œ License & Disclaimer

License: MIT License - See LICENSE for details

โš ๏ธ Prohibited Use & Anti-Abuse Policy

This tool is strictly prohibited for:

  • Commercial use or profit-making activities
  • Batch operations or automated abuse of any scale
  • Market disruption or malicious competition
  • Violations of Google's Terms of Service
  • Violations of Microsoft's Terms of Service

Consequences of Abuse: Violations may result in permanent account suspension, legal liability, and all consequences are the sole responsibility of the user.

Legitimate Use Only: This project is intended solely for personal learning, technical research, and non-commercial educational purposes.

๐Ÿ“– Full Disclaimer: DISCLAIMER_EN.md


โœจ Features

  • โœ… Full OpenAI API compatibility - Seamless integration with existing tools
  • โœ… Multi-account load balancing - Round-robin with automatic failover
  • โœ… Automated account management - Auto registration and login with DuckMail and Microsoft email integration, supports headless browser mode
  • โœ… Streaming output - Real-time responses
  • โœ… Multimodal input - 100+ file types (images, PDF, Office docs, audio, video, code, etc.)
  • โœ… Image generation & image-to-image - Configurable models, Base64 or URL output
  • โœ… Smart file handling - Auto file type detection, supports URL and Base64
  • โœ… Logging & monitoring - Real-time status and statistics
  • โœ… Proxy support - Configure in the admin settings
  • โœ… Built-in admin panel - Online configuration and account management
  • โœ… Optional PostgreSQL backend โ€” persists accounts/settings/stats thanks PR

๐Ÿค– Model Capabilities

Model ID Vision Native Web File Multimodal Image Gen
gemini-auto โœ… โœ… โœ… Optional
gemini-2.5-flash โœ… โœ… โœ… Optional
gemini-2.5-pro โœ… โœ… โœ… Optional
gemini-3-flash-preview โœ… โœ… โœ… Optional
gemini-3-pro-preview โœ… โœ… โœ… Optional

๐Ÿš€ Quick Start

Method 1: Using Setup Script (Recommended)

Linux/macOS:

git clone https://github.com/Dreamy-rain/gemini-business2api.git
cd gemini-business2api
bash setup.sh

cp .env.example .env
# Edit .env to set ADMIN_KEY

source .venv/bin/activate  # Linux/macOS
# .venv\Scripts\activate.bat  # Windows

python main.py

# Run with pm2 in background
# Make sure you're in the project directory
pm2 start main.py --name gemini-api --interpreter ./.venv/bin/python3

Windows:

git clone https://github.com/Dreamy-rain/gemini-business2api.git
cd gemini-business2api
setup.bat

copy .env.example .env
# Edit .env to set ADMIN_KEY

source .venv/bin/activate  # Linux/macOS
# .venv\Scripts\activate.bat  # Windows

python main.py

# Run with pm2 in background
# Make sure you're in the project directory
pm2 start main.py --name gemini-api --interpreter ./.venv/bin/python3

Script Features:

  • โœ… Automatically syncs latest code
  • โœ… Updates frontend to latest versions
  • โœ… Creates/updates Python virtual environment
  • โœ… Installs/updates dependencies
  • โœ… Automatically creates .env config file (if not exists)

First Installation: After completion, edit .env to set ADMIN_KEY, then run python main.py

Update Project: Simply run the same command, the script will automatically update all components (code, dependencies, frontend)

Method 2: Manual Deployment

git clone https://github.com/Dreamy-rain/gemini-business2api.git
cd gemini-business2api

# Build frontend
cd frontend
npm install
npm run build
cd ..

# Create virtual environment (recommended)
python3 -m venv .venv
source .venv/bin/activate  # Linux/macOS
# .venv\Scripts\activate.bat  # Windows

# Install Python dependencies
pip install -r requirements.txt
cp .env.example .env
# win copy .env.example .env
# Edit .env to set ADMIN_KEY
python main.py

# Run with pm2 in background
# Make sure you're in the project directory
pm2 start main.py --name gemini-api --interpreter ./.venv/bin/python3

Method 3: Docker Compose (Recommended for Production)

Supports ARM64 and AMD64 architectures

# 1. Clone the repository
git clone https://github.com/Dreamy-rain/gemini-business2api.git
cd gemini-business2api

# 2. Configure environment variables
cp .env.example .env
# Edit .env to set ADMIN_KEY

# 3. Start the service
docker-compose up -d

# 4. View logs
docker-compose logs -f

# 5. Update to the latest version
docker-compose pull && docker-compose up -d

Thanks to PR #9 for optimizing the Dockerfile build

Optional: Database Persistence (Local / HF Spaces)

  • Recommended on HF Spaces (free tier) to avoid data loss after restart
  • Set DATABASE_URL=postgresql://user:password@host/dbname?sslmode=require
    • Local: put it in .env
    • HF Spaces: Settings -> Variables/Secrets
  • Accounts/settings/stats are stored in the database
  • Keep the connection string secret (it includes credentials)
#  Get DATABASE_URL from Neon (recommended)
1. Open https://neon.tech and sign in
2. Create project -> choose a region
3. Open the project page, copy the Connection string
4. Example:
   postgresql://user:password@ep-xxx.neon.tech/dbname?sslmode=require

Access

  • Admin Panel: http://localhost:7860/ (Login with ADMIN_KEY)
  • OpenAI-compatible API: http://localhost:7860/v1/chat/completions

Configuration Tips

  • Account config prioritizes ACCOUNTS_CONFIG env var, or can be entered in admin panel and saved to data/accounts.json.
  • For authentication, configure API_KEY in the admin settings to protect /v1/chat/completions.

Documentation

๐Ÿ“ธ Screenshots

Admin System

Admin System 1 Admin System 2
Admin System 3 Admin System 4
Admin System 5 Admin System 6

Image Effects

Image Effects 1 Image Effects 2
Image Effects 3 Image Effects 4

โญ Star History

Star History Chart

If this project helps you, please give it a โญ Star!