Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

MasuRii/AIstudioProxyAPI-EN

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

614 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

ComponentVersion RequirementsRecommended VersionDescription
Python≥3.9, <4.03.10+ or 3.11+Docker environment uses 3.10
Operating SystemWindows / macOS / Linux-Full cross-platform support, Docker supports x86_64 and ARM64
Memory≥2GB≥4GBBrowser automation required
NetworkStable internet connection-Configurable proxy to access Google AI Studio
Dependency ManagementPoetryLatest versionModern Python dependency management tool
Type CheckingPyright (optional)Latest versionUsed 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-compatibletools/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 themodel field in API requests
  • Complete Parameter Control: Supports all major parameters liketemperature,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 theQuick Start section below for deployment, which should take 15-30 minutes to complete.

Three-Step Quick Deployment

# 1️⃣ Clone and installgit clone https://github.com/MasuRii/AIstudioProxyAPI.gitcd AIstudioProxyAPIpoetry install# Automatically creates virtual environment and installs dependencies# 2️⃣ Configure environmentcp .env.example .envnano .env# Edit configuration (optional, default configuration can be used). Set AUTO_SAVE_AUTH=true to save authentication.# 3️⃣ Initial authentication and startpoetry 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 checkcurl http://127.0.0.1:2048/health# Get model listcurl http://127.0.0.1:2048/v1/models# Test chat (non-streaming) - Gemini 3.1 Pro curl -X POST http://127.0.0.1:2048/v1/chat/completions \   -H"Content-Type: application/json" \   -d'{"model":"gemini-3.1-pro","messages":[{"role":"user","content":"Hello"}]}'# Test chat with thinking level (Gemini 3.x models support thinking levels) curl -X POST http://127.0.0.1:2048/v1/chat/completions \   -H"Content-Type: application/json" \   -d'{"model":"gemini-3.1-pro","messages":[{"role":"user","content":"Explain quantum computing"}],"thinking_level":"high"}'# Test streaming chatcurl -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# Alternative models (all valid)# - gemini-3.1-pro-preview# - gemini-3-pro-preview# - gemini-2.5-pro# - gemini-2.5-flash

Access Web UI

Open your browser and navigate tohttp://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/Linuxcurl -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.gitcd AIstudioProxyAPI

3. Install Dependencies

poetry install

4. Install Browser and Camoufox

# Activate Poetry environmentpoetry shell# Install Playwright browserplaywright install firefox# Download Camoufox data filescamoufox fetch# Or use alternative methodpython fetch_camoufox_data.py

🎮 Running & Debugging

Daily Running Modes

CommandDescriptionApplicable Scenarios
python gui_launcher.pyGUI launcherNew users, visual configuration
python launch_camoufox.py --headlessHeadless modeDaily use, servers
python launch_camoufox.pyNormal modeView browser window
python launch_camoufox.py --debugDebug modeInitial authentication, troubleshooting
python launch_camoufox.py --virtual-displayVirtual display modeLinux non-GUI environment

⚙️ Configuration Management

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

Quick Configuration

# 1. Copy configuration templatecp .env.example .env# 2. Edit configuration filenano .env# or use other editor

Main Configuration Categories

CategoryExample ConfigurationDescription
Port ConfigurationPORT=2048FastAPI service port
STREAM_PORT=3120Streaming proxy port (set to 0 to disable)
Proxy ConfigurationUNIFIED_PROXY_CONFIG=http://127.0.0.1:7890HTTP/HTTPS proxy
Log ConfigurationSERVER_LOG_LEVEL=INFOLog level (DEBUG/INFO/WARNING)
DEBUG_LOGS_ENABLED=falseEnable debug logs
API ParametersDEFAULT_TEMPERATURE=1.0Default temperature parameter
DEFAULT_MAX_OUTPUT_TOKENS=65536Default max output tokens
Gemini 3.x ConfigurationDEFAULT_THINKING_LEVEL_PRO=highDefault thinking level for Gemini 3 Pro (low, high)
DEFAULT_THINKING_LEVEL_FLASH=highDefault thinking level for Gemini 3 Flash (minimal, low, medium, high)
Function CallingFUNCTION_CALLING_MODE=autoMode: auto, native, or emulated
FUNCTION_CALLING_THOUGHT_SIGNATURE=trueEnable thoughtSignature for Gemini 3.x compatibility
Auth RotationAUTO_ROTATE_AUTH_PROFILE=trueAuto-switch auth profiles on quota issues
QUOTA_SOFT_LIMIT=850000Soft quota limit (triggers rotation after stream)
QUOTA_HARD_LIMIT=950000Hard quota limit (triggers immediate rotation)
Cookie RefreshCOOKIE_REFRESH_ENABLED=trueAuto-refresh browser cookies
Timeout ConfigurationRESPONSE_COMPLETION_TIMEOUT=600000Response timeout (milliseconds)
Authentication ConfigurationAUTO_SAVE_AUTH=falseAuto-save authentication files

Supported Models

ModelContext WindowMax OutputThinking LevelsDescription
Gemini 3.1 Pro Preview1M tokens64Klow,high (2-level)Latest Pro model with advanced reasoning
Gemini 3 Pro Preview1M tokens64Klow,high (2-level)Advanced reasoning model
Gemini 2.5 Pro1M tokens64KN/AHigh-performance reasoning
Gemini 2.5 Flash1M tokens64KN/AFast, cost-effective

Note: Usethinking_level parameter with Gemini 3.x models to control reasoning depth. See.env.example for full configuration options.


📚 Documentation

Note: Detailed documentation is maintained within the codebase. Refer to the following resources:

  • Configuration Reference:.env.example - Complete list of all configuration options with descriptions
  • Code Comments: Inline documentation throughout the source code
  • Docker Deployment: SeeDocker README andDocker Deployment Guide
  • License:AGPLv3

Key Configuration Files

FilePurpose
.env.exampleComplete configuration template with all options documented
docker/README.mdDocker Compose quick start guide
docker/README-Docker.mdDetailed Docker deployment documentation
LICENSEAGPLv3 license terms

🐳 Docker Deployment

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

🚀 Quick Docker Deployment

# 1. Prepare configuration filecd dockercp .env.docker .envnano .env# Edit configuration# 2. Start using Docker Composedocker compose up -d# 3. View logsdocker compose logs -f# 4. Version update (in docker directory)bash update.sh

About Camoufox

This project usesCamoufox 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

TakingOpen 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 exampleaistudio-gemini-py
  5. API Base URL: Enterhttp://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

  • Python91.6%
  • TypeScript6.8%
  • CSS1.2%
  • PowerShell0.2%
  • Shell0.1%
  • Dockerfile0.1%

[8]ページ先頭

©2009-2026 Movatter.jp