General Introduction
AIstudioProxyAPI is an open source project that uses Node.js and Playwright technology to emulate the OpenAI API by simulating the Google AI Studio web-based Gemini Model dialog functionality into a standard API interface. Developers can utilize this proxy service to allow clients that support the OpenAI API (e.g., Open WebUI, NextChat) to directly access the Google AI Studio The unlimited amount of features. The project does not require complex configuration and is suitable for developers who want to quickly integrate Google AI Studio capabilities. The current project is personally maintained, is updated infrequently, and does not support headless mode, so you need to manually ensure that the Chrome debugging port is available.
Function List
- furnish
/v1/chat/completions
cap (a poem)/v1/models
endpoints, compatible with the OpenAI API client. - Streaming response support (
stream=true
) to achieve the typewriter effect. - Support for non-streaming responses (
stream=false
), which returns the full JSON at once. - Automatically optimize user input prompt words and adapt the output format of Google AI Studio.
- Automatically starts and connects to the Chrome instance, sets the debug port and window size.
- Provides interactive options for handling port conflicts or connecting to existing Chrome instances.
Using Help
Installation process
AIstudioProxyAPI is simple to deploy, but you need to make sure that your environment is properly configured. Below are the detailed steps:
- clone warehouse
Run the following command in the terminal to get the project code:git clone https://github.com/CJackHwang/AIstudioProxyAPI cd AIstudioProxyAPI
- Installation of dependencies
Project dependenciesexpress
,cors
,playwright
cap (a poem)@playwright/test
. Choose one of the following commands depending on your package manager:npm install # 或 yarn install # 或 pnpm install
After the installation is complete, the dependency is automatically configured that
@playwright/test
Provides assertion functionality. - Starting services
Run the following command to start the agent service:node auto_connect_aistudio.cjs
The script will:
- Check that the dependencies are complete.
- Verify Chrome Debug Port (default)
8848
) whether or not it is free. - Setting the Chrome window size (default width)
460px
). - Automatically launch Chrome and open the Google AI Studio page.
If the port is occupied, the script prompts for the option to connect to an existing Chrome instance or clear the port and retry. Make sure to manually log in to the Google AI Studio page to complete authentication.
Using the main functions
The core of AIstudioProxyAPI is to make Google AI Studio's Gemini modeling capabilities available to clients via an OpenAI API compliant interface. Here's how it works:
- Configuring the Client
In clients that support the OpenAI API (such as Open WebUI), set the API address to the address of the proxy service (default)http://localhost:2048
). No need to change the client code, the interfaces are fully compatible. - Send a dialog request
Use the client to send a dialog request in the same format as the OpenAI API. Example:{ "model": "gemini", "messages": [ {"role": "system", "content": "你是一个助手"}, {"role": "user", "content": "请解释量子力学"} ], "stream": true }
- set up
stream=true
Get streaming responses, suitable for real-time conversations. - set up
stream=false
Get the full JSON response, suitable for one-time processing.
- set up
- Optimize Cue Words
The proxy service automatically wraps the user input, adding specific tags (such as<<<START_RESPONSE>>>
) to ensure that Google AI Studio output is in the expected format. Developers don't need to manually adjust the cue words. - Managing Chrome instances
After launching, the Chrome window must remain open and the Google AI Studio page must not crash. If the page is unresponsive, close all related processes (node
cap (a poem)chrome
), re-run thenode auto_connect_aistudio.cjs
The
Featured Function Operation
- Streaming Response: Setting on the client side
stream=true
The response is displayed verbatim with a typewriter effect, suitable for interactive applications. - Port Conflict Handling: The script detects
8848
When the port is occupied, the user is prompted to choose between connecting to an existing Chrome instance or clearing the port. - Window resizing: If
460px
Width does not fit the monitor, can be modifiedauto_connect_aistudio.cjs
hit the nail on the head--window-size
Parameters.
Troubleshooting
- Page Load Failure: Check the network connection and try to access it manually
https://aistudio.google.com/prompts/new_chat
and log in. - port occupancy: Run
lsof -i :2048
Check occupancy programs, close or changeserver.cjs
hit the nail on the headSERVER_PORT
The - Playwright is not ready.: Make sure the Chrome window is not closed and re-run the startup script.
application scenario
- Rapid integration of AI conversations
Developers who want to add AI conversations to their apps but are limited by the OpenAI API quota, AIstudioProxyAPI lets developers take advantage of Google AI Studio's free quota to quickly implement functionality through the familiar OpenAI API interface. - Local Development and Testing
Development teams can emulate the OpenAI API through AIstudioProxyAPI when testing AI dialog functionality in their local environments, eliminating the need to purchase additional API quotas and reducing costs. - Education and Research
Students or researchers need to experiment with large model dialog capabilities, but lack API access.AIstudioProxyAPI provides an easy way to access Gemini models for academic research.
QA
- Which clients does AIstudioProxyAPI support?
Any client that supports the OpenAI API (e.g. Open WebUI, NextChat) can be used without modifying the client code. - Why is headless mode not supported?
Google AI Studio's automated detection restricts headless mode to an interfaced Chrome instance. - How to deal with occupied ports?
probe2048
maybe8848
port occupancy, close conflicting programs or modifyserver.cjs
The port configuration in the - Does the service require continuous networking?
Yes, the proxy service requires internet access to the Google AI Studio page to ensure the page loads properly.