Skip to content

[EN] OpenAI-compatible proxy for Google AI Studio using FastAPI, Playwright & Camoufox. Simulates human requests via web automation.

License

Notifications You must be signed in to change notification settings

MasuRii/AIstudioProxyAPI-EN

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI Studio Proxy API

This is a Python-based proxy server that converts Google AI Studio's web interface into an OpenAI-compatible API. Through Camoufox (anti-fingerprinting Firefox) and Playwright automation, it provides stable API access.

This fork is the primary English version of the original project.

This project is generously sponsored by ZMTO with server support. Visit their website: https://zmto.com/


Acknowledgements

The birth and development of this project cannot be separated from the generous support and wisdom contributions of the following individuals, organizations, and communities:

At the same time, we sincerely thank every friend who has silently contributed to this project through submitting Issues, providing suggestions, sharing usage experiences, contributing code fixes, and other ways. It is your joint efforts that make this project better!


This is the currently maintained Python version.

๐Ÿ“Š Compatibility Matrix

Component Version Requirements Recommended Version Description
Python โ‰ฅ3.9, <4.0 3.10+ or 3.11+ Docker environment uses 3.10
Operating System Windows / macOS / Linux - Full cross-platform support, Docker supports x86_64 and ARM64
Memory โ‰ฅ2GB โ‰ฅ4GB Browser automation required
Network Stable internet connection - Configurable proxy to access Google AI Studio
Dependency Management Poetry Latest version Modern Python dependency management tool
Type Checking Pyright (optional) Latest version Used for type checking and IDE support during development

System Requirements

  • Python: >=3.9, <4.0 (recommend 3.10+ for best performance, Docker environment uses 3.10)
  • Dependency Management: Poetry (modern Python dependency management tool, replacement for traditional requirements.txt)
  • Type Checking: Pyright (optional, used for type checking and IDE support during development)
  • Operating System: Windows, macOS, Linux (full cross-platform support, Docker deployment supports x86_64 and ARM64)
  • Memory: Recommend 2GB+ available memory (browser automation required)
  • Network: Stable internet connection to access Google AI Studio (proxy configuration supported)

Main Features

  • OpenAI Compatible API: Supports /v1/chat/completions endpoint, fully compatible with OpenAI clients and third-party tools
  • Native Function Calling: Full OpenAI-compatible tools/tool_calls support via AI Studio's built-in function calling UI, with automatic fallback to text-based emulation ๐Ÿ†•
  • Three-Layer Streaming Response Mechanism: Integrated streaming proxy โ†’ external Helper service โ†’ Playwright page interaction multiple guarantees
  • Smart Model Switching: Dynamically switch models in AI Studio through the model field in API requests
  • Complete Parameter Control: Supports all major parameters like temperature, max_output_tokens, top_p, stop, reasoning_effort
  • Anti-Fingerprinting Detection: Uses Camoufox browser to reduce the risk of being detected as automated scripts
  • Script Injection Feature v3.0: Uses Playwright native network interception, supports Tampermonkey script dynamic mounting, 100% reliable
  • Modern Web UI: Built-in testing interface, supports real-time chat, status monitoring, hierarchical API key management
  • Graphical Interface Launcher: Provides feature-rich GUI launcher, simplifying configuration and process management
  • Flexible Authentication System: Supports optional API key authentication, fully compatible with OpenAI standard Bearer token format
  • Modular Architecture: Clear modular separation design, api_utils/, browser_utils/, config/ and other independent modules
  • Unified Configuration Management: Based on .env file unified configuration, supports environment variable overrides, Docker compatible
  • Auth profile smart rotation: Automatically rotates authentication profiles to avoid rate limits and improve stability.
  • Quota detection with graceful shutdown: The system can detect when a quota is reached and will gracefully shut down services to prevent errors.
  • Modern Development Tools: Poetry dependency management + Pyright type checking, providing excellent development experience
  • Integrated Frontend: A new React-based frontend for better user experience.

System Architecture

graph TD
    subgraph "User End"
        User["User"]
        WebUI["Web UI (Browser)"]
        API_Client["API Client"]
    end

    subgraph "Launch & Config"
        GUI_Launch["gui_launcher.py (GUI Launcher)"]
        CLI_Launch["launch_camoufox.py (Command Line Launch)"]
        EnvConfig[".env (Unified Configuration)"]
        KeyFile["auth_profiles/key.txt (API Keys)"]
        ConfigDir["config/ (Configuration Module)"]
    end

    subgraph "Core Application"
        FastAPI_App["api_utils/app.py (FastAPI Application)"]
        Routes["api_utils/routers/* (Route Handling)"]
        RequestProcessor["api_utils/request_processor.py (Request Processing)"]
        AuthUtils["api_utils/auth_utils.py (Authentication Management)"]
        PageController["browser_utils/page_controller.py (Page Control)"]
        ScriptManager["browser_utils/script_manager.py (Script Injection)"]
        ModelManager["browser_utils/model_management.py (Model Management)"]
        StreamProxy["stream/ (Streaming Proxy Server)"]
    end

    subgraph "External Dependencies"
        CamoufoxInstance["Camoufox Browser (Anti-Fingerprinting)"]
        AI_Studio["Google AI Studio"]
        UserScript["Tampermonkey Script (Optional)"]
    end

    User -- "Run" --> GUI_Launch
    User -- "Run" --> CLI_Launch
    User -- "Access" --> WebUI

    GUI_Launch -- "Starts" --> CLI_Launch
    CLI_Launch -- "Starts" --> FastAPI_App
    CLI_Launch -- "Configures" --> StreamProxy

    API_Client -- "API Request" --> FastAPI_App
    WebUI -- "Chat Request" --> FastAPI_App

    FastAPI_App -- "Reads Config" --> EnvConfig
    FastAPI_App -- "Uses Routes" --> Routes
    AuthUtils -- "Validates Key" --> KeyFile
    ConfigDir -- "Provides Settings" --> EnvConfig

    Routes -- "Processes Request" --> RequestProcessor
    Routes -- "Auth Management" --> AuthUtils
    RequestProcessor -- "Controls Browser" --> PageController
    RequestProcessor -- "Uses Proxy" --> StreamProxy

    PageController -- "Model Management" --> ModelManager
    PageController -- "Script Injection" --> ScriptManager
    ScriptManager -- "Loads Script" --> UserScript
    ScriptManager -- "Enhances" --> CamoufoxInstance
    PageController -- "Automates" --> CamoufoxInstance
    CamoufoxInstance -- "Accesses" --> AI_Studio
    StreamProxy -- "Forwards Request" --> AI_Studio

    AI_Studio -- "Response" --> CamoufoxInstance
    AI_Studio -- "Response" --> StreamProxy

    CamoufoxInstance -- "Returns Data" --> PageController
    StreamProxy -- "Returns Data" --> RequestProcessor

    FastAPI_App -- "API Response" --> API_Client
    FastAPI_App -- "UI Response" --> WebUI
Loading

๐Ÿš€ Quick Start

New users are recommended to follow the Quick Start Guide for deployment, which should take 15-30 minutes to complete.

Three-Step Quick Deployment

# 1๏ธโƒฃ Clone and install
git clone https://github.com/MasuRii/AIstudioProxyAPI.git
cd AIstudioProxyAPI
poetry install  # Automatically creates virtual environment and installs dependencies

# 2๏ธโƒฃ Configure environment
cp .env.example .env
nano .env  # Edit configuration (optional, default configuration can be used). Set AUTO_SAVE_AUTH=true to save authentication.

# 3๏ธโƒฃ Initial authentication and start
poetry run python launch_camoufox.py --debug  # Initial authentication (requires Google login)
# After successful authentication, move auth_profiles/saved/*.json to auth_profiles/active/
# Then run in headless mode:
poetry run python launch_camoufox.py --headless

Quick Test

# Health check
curl http://127.0.0.1:2048/health

# Get model list
curl http://127.0.0.1:2048/v1/models

# Test chat (non-streaming)
curl -X POST http://127.0.0.1:2048/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-3-pro-preview","messages":[{"role":"user","content":"Hello"}]}'

# Test streaming chat
curl -X POST http://127.0.0.1:2048/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-2.5-pro","messages":[{"role":"user","content":"Tell me a story"}],"stream":true}' --no-buffer

Access Web UI

Open your browser and navigate to http://127.0.0.1:2048/ to use the built-in web chat interface.


๐Ÿ“ฆ Installation & Dependency Management

Prerequisites

  • Python 3.9+ (recommend 3.10 or 3.11)
  • 2GB+ available memory
  • Stable internet connection

One-Click Installation Script

macOS/Linux:

curl -sSL https://raw.githubusercontent.com/MasuRii/AIstudioProxyAPI/main/scripts/install.sh | bash

Windows (PowerShell):

iwr -useb https://raw.githubusercontent.com/MasuRii/AIstudioProxyAPI/main/scripts/install.ps1 | iex

Manual Installation Steps

1. Install Poetry

# macOS/Linux
curl -sSL https://install.python-poetry.org | python3 -

# Windows (PowerShell)
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

2. Clone Project

git clone https://github.com/MasuRii/AIstudioProxyAPI.git
cd AIstudioProxyAPI

3. Install Dependencies

poetry install

4. Install Browser and Camoufox

# Activate Poetry environment
poetry shell

# Install Playwright browser
playwright install firefox

# Download Camoufox data files
camoufox fetch
# Or use alternative method
python fetch_camoufox_data.py

๐ŸŽฎ Running & Debugging

Daily Running Modes

Command Description Applicable Scenarios
python gui_launcher.py GUI launcher New users, visual configuration
python launch_camoufox.py --headless Headless mode Daily use, servers
python launch_camoufox.py Normal mode View browser window
python launch_camoufox.py --debug Debug mode Initial authentication, troubleshooting
python launch_camoufox.py --virtual-display Virtual display mode Linux non-GUI environment

โš™๏ธ Configuration Management

The project uses .env file for configuration management, with all configuration items centrally managed.

Quick Configuration

# 1. Copy configuration template
cp .env.example .env

# 2. Edit configuration file
nano .env  # or use other editor

Main Configuration Categories

Category Example Configuration Description
Port Configuration PORT=2048 FastAPI service port
STREAM_PORT=3120 Streaming proxy port (set to 0 to disable)
Proxy Configuration UNIFIED_PROXY_CONFIG=http://127.0.0.1:7890 HTTP/HTTPS proxy
Log Configuration SERVER_LOG_LEVEL=INFO Log level (DEBUG/INFO/WARNING)
DEBUG_LOGS_ENABLED=false Enable debug logs
API Parameters DEFAULT_TEMPERATURE=1.0 Default temperature parameter
DEFAULT_MAX_OUTPUT_TOKENS=65536 Default max output tokens
Timeout Configuration RESPONSE_COMPLETION_TIMEOUT=300000 Response timeout (milliseconds)
Authentication Configuration AUTO_SAVE_AUTH=false Auto-save authentication files

๐Ÿ“š Detailed Documentation

๐Ÿš€ Quick Start

๐Ÿ”ง Feature Usage

๐ŸŒ Platform & Deployment


๐Ÿณ Docker Deployment

This project supports deployment through Docker, using Poetry for dependency management, fully supports .env configuration files!

๐Ÿš€ Quick Docker Deployment

# 1. Prepare configuration file
cd docker
cp .env.docker .env
nano .env  # Edit configuration

# 2. Start using Docker Compose
docker compose up -d

# 3. View logs
docker compose logs -f

# 4. Version update (in docker directory)
bash update.sh

About Camoufox

This project uses Camoufox to provide browser instances with enhanced anti-fingerprinting capabilities.


๐Ÿ”‘ Core Concepts

Runtime Component Description

AI Studio Proxy API consists of multiple components working together:

  1. FastAPI Main Server (server.py): Provides OpenAI-compatible REST API endpoints.
  2. Camoufox Browser: Provides Firefox browser instance with anti-fingerprinting capabilities.
  3. Playwright Automation Engine: Controls browser to perform automation operations.
  4. Integrated Streaming Proxy Service (stream/): Provides low-latency streaming response proxy.
  5. GUI Launcher (gui_launcher.py): Provides graphical startup and configuration interface.

Client Configuration Example

Taking Open WebUI as an example:

  1. Open Open WebUI
  2. Go to "Settings" -> "Connection"
  3. In the "Model" section, click "Add Model"
  4. Model Name: Enter the name you want, for example aistudio-gemini-py
  5. API Base URL: Enter http://127.0.0.1:2048/v1
  6. API Key: Leave empty or enter any characters
  7. Save settings and start chatting

Contributing

Welcome to submit Issues and Pull Requests!

License

AGPLv3

Star History Chart

Development is difficult, please support the author

If you find this project helpful and wish to support the author's continuous development, welcome to donate through the following methods. Your support is our greatest encouragement!

Development is difficult, please support the author

About

[EN] OpenAI-compatible proxy for Google AI Studio using FastAPI, Playwright & Camoufox. Simulates human requests via web automation.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 91.0%
  • TypeScript 7.3%
  • CSS 1.2%
  • PowerShell 0.2%
  • Shell 0.2%
  • Dockerfile 0.1%