Skip to content

yaron4u/AIstudioProxyAPIClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Studio Proxy API + Client

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.

Overview

This is an English translation and adaptation of the AIstudioProxyAPI project. Special thanks to the original author for creating this excellent proxy solution.

Main Features

  • OpenAI Compatible API: Fully compatible with /v1/chat/completions endpoint 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

System Requirements

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

Key Additions

  • gemini_client.py: A Python client library for easy integration and cross-model validation
  • gemeni_reviewer.py: Code review automation script using the proxy API
  • AGENTS.md: AI system prompts and behavior guidelines - feel free to enhance and improve them

Quick Start

Installation

# 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

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

System Architecture

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
Loading

Run Modes

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

⚙️ Configuration

The project uses .env file for unified configuration management:

cp AIstudioProxyAPI/.env.example .env
# Edit .env file with your configuration

Core 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

🐳 Docker Deployment

cd AIstudioProxyAPI/docker
cp .env.docker .env
# Edit .env file

docker compose up -d
docker compose logs -f

# Version update
bash update.sh

Detailed Guide: Docker Deployment Guide

📚 Documentation

Getting Started

Feature Usage

Advanced Configuration

Development Related

Client Configuration Example

Using Open WebUI as an example:

  1. Go to "Settings" → "Connections"
  2. Add model, API Base URL: http://127.0.0.1:2048/v1
  3. API Key: Leave empty or any character
  4. Save and start chatting

Usage Examples

Using the Gemini Client

from gemini_client import GeminiClient

client = GeminiClient()
response = client.ask("Explain quantum computing in simple terms")
print(response)

Code Review Automation

python gemeni_reviewer.py  # Reviews files listed in the script

Contributing

You'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.

Credits

License

See the LICENSE file in the aistudioproxy/AIstudioProxyAPI directory.

About

A FastAPI-based proxy server using Playwright and Camoufox that provides OpenAI API compatibility with full parameter forwarding. It automates browser interactions to route API requests to Google AI Studio's web interface, returning responses in standard OpenAI format.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors