中文文档 | English
A tool that wraps Google AI Studio web interface to provide OpenAI API, Gemini API, and Anthropic API compatible endpoints. The service acts as a proxy, converting API requests to browser interactions with the AI Studio web interface.
Clone the repository:
git clone https://github.com/iBUHub/AIStudioToAPI.git
cd AIStudioToAPI
Run the setup script:
npm run setup-auth
This script will:
Automatically download the Camoufox browser (a privacy-focused Firefox fork)
Launch the browser and navigate to AI Studio automatically
Save your authentication credentials locally
💡 Tip: If downloading the Camoufox browser fails or takes too long, you can manually download it from here, and set the environment variable
CAMOUFOX_EXECUTABLE_PATHto the path of the browser executable (both absolute and relative paths are supported).
Configure Environment Variables (Optional):
Copy .env.example in the root directory to .env, and modify settings in .env as needed (e.g., port, API Key).
Start the service:
npm start
The API server will be available at http://localhost:7860
After the service starts, you can access http://localhost:7860 in your browser to open the web console homepage, where you can view account status and service status.
⚠ Note: Running directly does not support adding accounts via VNC online. You need to use the
npm run setup-authscript to add accounts. VNC login is only available in Docker deployments.
Deploy using Docker without pre-extracting authentication credentials.
docker run -d \ --name aistudio-to-api \ -p 7860:7860 \ -v /path/to/auth:/app/configs/auth \ -e API_KEYS=your-api-key-1,your-api-key-2 \ -e TZ=Asia/Shanghai \ --restart unless-stopped \ ghcr.io/ibuhub/aistudio-to-api:latest
💡 Tip: If
ghcr.iois slow or unavailable, you can use the Docker Hub image:ibuhub/aistudio-to-api:latest.
Parameters:
-p 7860:7860: API server port (if using a reverse proxy, strongly consider 127.0.0.1:7860)-v /path/to/auth:/app/configs/auth: Mount directory containing auth files-e API_KEYS: Comma-separated list of API keys for authentication-e TZ=Asia/Shanghai: Timezone for logs (optional, defaults to system timezone)Create a docker-compose.yml file:
name: aistudio-to-api
services:
app:
image: ghcr.io/ibuhub/aistudio-to-api:latest
container_name: aistudio-to-api
ports:
- 7860:7860
restart: unless-stopped
volumes:
- ./auth:/app/configs/auth
environment:
API_KEYS: your-api-key-1,your-api-key-2
TZ: Asia/Shanghai # Timezone for logs (optional)
Start the service:
sudo docker compose up -d
View logs:
sudo docker compose logs -f
Stop the service:
sudo docker compose down
Proxy Configuration (Optional): If you need to use a proxy to access Google services, add -e HTTP_PROXY=http://your-proxy:port -e HTTPS_PROXY=http://your-proxy:port to the Docker command, or add these environment variables to your docker-compose.yml.
If you prefer to build the Docker image yourself, you can use the following commands:
Build the image:
docker build -t aistudio-to-api .
Run the container:
docker run -d \ --name aistudio-to-api \ -p 7860:7860 \ -v /path/to/auth:/app/configs/auth \ -e API_KEYS=your-api-key-1,your-api-key-2 \ -e TZ=Asia/Shanghai \ --restart unless-stopped \ aistudio-to-api
After deployment, you need to add Google accounts using one of these methods:
Method 1: VNC-Based Login (Recommended)
http://your-server:7860) and click the "Add User" buttonauth-N.json (N starts from 0)Method 2: Upload Auth Files
npm run setup-auth on your local machine to generate auth files/path/to/auth directory💡 Tip: You can also download auth files from an existing container and upload them to a new container. Click the "Download Auth" button for the corresponding account in the web console to download the auth file.
⚠ Environment variable-based auth injection is no longer supported.
If you need to access via a domain name or want unified management at the reverse proxy layer (e.g., configure HTTPS, load balancing, etc.), you can use Nginx.
📖 For detailed Nginx configuration instructions, see: Nginx Reverse Proxy Configuration
Deploy directly on Claw Cloud Run, a fully managed container platform.
📖 For detailed deployment instructions, see: Deploy on Claw Cloud Run
Deploy on the Zeabur container platform.
⚠ Note: Zeabur's free tier provides only $5 credits per month, which is not enough to run 24/7. Please pause the service when not in use!
📖 For detailed deployment instructions, see: Deploy on Zeabur
This endpoint is processed and then forwarded to the official Gemini API format endpoint.
GET /v1/models: List models.POST /v1/chat/completions: Chat completion and image generation, supports non-streaming, real streaming, and fake streaming.This endpoint is forwarded to the official Gemini API format endpoint.
GET /v1beta/models: List available Gemini models.POST /v1beta/models/{model_name}:generateContent: Generate content, images, and speech.POST /v1beta/models/{model_name}:streamGenerateContent: Stream content, image, and speech generation, supports real and fake streaming.POST /v1beta/models/{model_name}:batchEmbedContents: Batch generate text embedding vectors.POST /v1beta/models/{model_name}:predict: Imagen series models image generation.This endpoint forwards requests to the official Gemini API format endpoint.
GET /v1/models: List models.POST /v1/messages: Chat message completions, supports non-streaming, real streaming, and fake streaming.📖 For detailed API usage examples, see: API Usage Examples
| Variable | Description | Default |
|---|---|---|
API_KEYS | Comma-separated list of valid API keys for authentication. | 123456 |
PORT | API server port. | 7860 |
HOST | Server listening host address. | 0.0.0.0 |
ICON_URL | Custom favicon URL for the console. Supports ICO, PNG, SVG, etc. | /AIStudio_logo.svg |
SECURE_COOKIES | Enable secure cookies. true for HTTPS only, false for both HTTP and HTTPS. | false |
RATE_LIMIT_MAX_ATTEMPTS | Maximum failed login attempts allowed within the time window (0 to disable). | 5 |
RATE_LIMIT_WINDOW_MINUTES | Time window for rate limiting in minutes. | 15 |
CHECK_UPDATE | Enable version update check on page load (false to disable). | true |
LOG_LEVEL | Logging output level. Set to DEBUG for detailed debug logs. | INFO |
| Variable | Description | Default |
|---|---|---|
INITIAL_AUTH_INDEX | Initial authentication index to use on startup. | 0 |
ENABLE_AUTH_UPDATE | Whether to enable automatic auth credential updates. Defaults to enabled. The auth file will be automatically updated upon successful login/account switch and every 24 hours. Set to false to disable. | true |
MAX_RETRIES | Maximum number of retries for failed requests (only effective for fake streaming and non-streaming). | 3 |
RETRY_DELAY | Delay between retries in milliseconds. | 2000 |
SWITCH_ON_USES | Number of requests before automatically switching accounts (0 to disable). | 40 |
FAILURE_THRESHOLD | Number of consecutive failures before switching accounts (0 to disable). | 3 |
IMMEDIATE_SWITCH_STATUS_CODES | HTTP status codes that trigger immediate account switching (comma-separated, set to empty to disable). | 429,503 |
| Variable | Description | Default |
|---|---|---|
STREAMING_MODE | Streaming mode. real for real streaming, fake for fake streaming. | real |
FORCE_THINKING | Force enable thinking mode for all requests. | false |
FORCE_WEB_SEARCH | Force enable web search for all requests. | false |
FORCE_URL_CONTEXT | Force enable URL context for all requests. | false |
CAMOUFOX_EXECUTABLE_PATH | Path to the Camoufox browser executable (supports both absolute and relative paths). Only required if manually downloaded. | Auto-detected |
Edit configs/models.json to customize available models and their settings.
This project is a fork of ais2api by Ellinav, and fully adopts the CC BY-NC 4.0 license used by the upstream project. All usage, distribution, and modification activities must comply with all terms of the original license. See the full license text in LICENSE.
We would like to thank all developers who have contributed their time, effort, and wisdom to this project.