Convert Google AI Studio web interface to an OpenAI-compatible API proxy server. Provides stable API access through Camoufox (anti-fingerprinting Firefox) and Playwright automation. Enhanced with a Python client library (gemini_client.py) for seamless integration and automated workflows.
This is an English translation and adaptation of the AIstudioProxyAPI project. Special thanks to the original author for creating this excellent proxy solution.
- OpenAI Compatible API: Fully compatible with
/v1/chat/completionsendpoint and mainstream clients - Three-layer Streaming Response Mechanism: Integrated streaming proxy → External Helper → Playwright page interaction
- Intelligent Model Switching: Dynamically switch AI Studio models with complete parameter control
- Anti-fingerprinting Detection: Camoufox browser reduces detection risk
- Modern Web UI: Built-in testing interface, status monitoring, API key management
- Graphical Interface Launcher: GUI launcher simplifies configuration and process management
- Script Injection v3.0: Playwright native network interception, supports dynamic mounting of userscripts
| Component | Requirement | Recommended |
|---|---|---|
| Python | ≥3.9, <4.0 | 3.10+ or 3.11+ |
| Dependency Management | Poetry | Latest version |
| Memory | ≥2GB | ≥4GB |
| Network | Stable internet | Configurable proxy |
gemini_client.py: A Python client library for easy integration and cross-model validationgemeni_reviewer.py: Code review automation script using the proxy APIAGENTS.md: AI system prompts and behavior guidelines - feel free to enhance and improve them
# 1️⃣ Clone and install
git clone https://github.com/yaron4u/AIstudioProxyAPIClient.git
cd AIstudioProxyAPI
poetry install
# 2️⃣ Configure environment
cp AIstudioProxyAPI/.env.example .env
# Edit .env file with your configuration (optional)
# 3️⃣ First authentication and startup
poetry run python AIstudioProxyAPI/launch_camoufox.py --debug # First authentication (requires Google login)
# After successful authentication, Ctrl+C to stop, then:
poetry run python AIstudioProxyAPI/launch_camoufox.py --headless# Health check
curl http://127.0.0.1:2048/health
# Get model list
curl http://127.0.0.1:2048/v1/models
# Test chat
curl -X POST http://127.0.0.1:2048/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gemini-2.5-pro-preview","messages":[{"role":"user","content":"Hello"}]}'Access http://127.0.0.1:2048/ to use the built-in Web UI.
graph TD
subgraph "Client Side"
User["User"]
WebUI["Web UI"]
API_Client["API Client"]
end
subgraph "Launch & Configuration"
GUI_Launch["gui_launcher.py"]
CLI_Launch["launch_camoufox.py"]
EnvConfig[".env Configuration"]
end
subgraph "Core Application"
FastAPI_App["FastAPI Application<br/>api_utils/"]
PageController["Page Controller<br/>browser_utils/"]
StreamProxy["Stream Proxy<br/>stream/"]
end
subgraph "External Dependencies"
CamoufoxInstance["Camoufox Browser"]
AI_Studio["Google AI Studio"]
end
User --> GUI_Launch & CLI_Launch
API_Client & WebUI --> FastAPI_App
FastAPI_App --> PageController & StreamProxy
PageController --> CamoufoxInstance --> AI_Studio
StreamProxy --> AI_Studio
| Command | Description | Scenario |
|---|---|---|
python gui_launcher.py |
GUI Launcher | Beginners, visual configuration |
python AIstudioProxyAPI/launch_camoufox.py --headless |
Headless mode | Daily use, server |
python AIstudioProxyAPI/launch_camoufox.py --debug |
Debug mode | First authentication, troubleshooting |
python AIstudioProxyAPI/launch_camoufox.py --virtual-display |
Virtual display | Linux GUI-less environment |
The project uses .env file for unified configuration management:
cp AIstudioProxyAPI/.env.example .env
# Edit .env file with your configuration| Configuration | Default | Description |
|---|---|---|
PORT |
2048 | FastAPI service port |
STREAM_PORT |
3120 | Stream proxy port (0 to disable) |
UNIFIED_PROXY_CONFIG |
- | HTTP/HTTPS proxy |
SERVER_LOG_LEVEL |
INFO | Log level |
Detailed Configuration: See Environment Variables Reference
cd AIstudioProxyAPI/docker
cp .env.docker .env
# Edit .env file
docker compose up -d
docker compose logs -f
# Version update
bash update.shDetailed Guide: Docker Deployment Guide
- Quick Start Guide - 15-minute quick deployment 🎯
- Installation Guide - Detailed installation steps
- Authentication Setup Guide - First authentication setup
- Daily Usage Guide - Daily usage
- API Usage Guide - API endpoints and configuration
- OpenAI Compatibility Notes - Differences with OpenAI API 🔄
- Client Integration Examples - Code examples 💻
- Web UI Usage Guide - Web interface features
- Script Injection Guide - Userscript functionality (v3.0)
- Environment Variables Configuration Guide - Configuration management ⭐
- Complete Environment Variables Reference - All configuration items 📋
- Streaming Processing Modes Explained - Three-layer response mechanism
- Advanced Configuration Guide - Advanced features
- Troubleshooting Guide - Problem solving
- Project Architecture Guide - Modular architecture
- Developer Guide - Poetry, Pyright workflow
Using Open WebUI as an example:
- Go to "Settings" → "Connections"
- Add model, API Base URL:
http://127.0.0.1:2048/v1 - API Key: Leave empty or any character
- Save and start chatting
from gemini_client import GeminiClient
client = GeminiClient()
response = client.ask("Explain quantum computing in simple terms")
print(response)python gemeni_reviewer.py # Reviews files listed in the scriptYou're welcome to create pull requests and contribute to this project! Whether it's:
- Bug fixes
- Feature enhancements
- Documentation improvements
- Additional client libraries
- Cross-model validation tools
All contributions are appreciated. Please ensure your code follows the project's standards and includes appropriate tests.
- Original project: CJackHwang/AIstudioProxyAPI
See the LICENSE file in the aistudioproxy/AIstudioProxyAPI directory.