This project provides a lightweight, self-hosted adapter that exposes a mock OpenAI-compatible API ( /v1/chat/completions and /v1/models) and translates the requests into automated UI interactions with Google's AI Studio, powered by Playwright.
- OpenAI API Compatibility: Emulates the
v1/chat/completionsendpoint for both streaming and non-streaming responses. - Model Support: Exposes a
/v1/modelsendpoint listing available Gemini models (gemini-2.5-pro,gemini-2.5-flash). - Cross-Platform: Works on both Windows and macOS, with automatic detection of Chrome's default installation path.
- Highly Configurable:
- API Request: Supports
max_tokens,top_p, andtemperatureon a per-request basis. - Application Settings: Configure browser automation, model capabilities (e.g., web search, code execution), and logging via
appsettings.jsonor environment variables.
- API Request: Supports
- Multi-Account Ready: Designed to cycle through multiple Google accounts to distribute usage.
- Structured Logging: Uses Serilog for structured, configurable, and easily searchable logs.
- UI Automation: Leverages the power of Playwright to interact with the AI Studio web interface reliably.
The adapter starts a local Kestrel web server that listens for incoming OpenAI API requests. When a /v1/chat/completions request is received, it performs the following steps:
- Launches or connects to a Chrome instance with remote debugging enabled.
- Navigates to Google AI Studio in a new page, cycling through configured user accounts.
- Selects the requested model (e.g.,
gemini-2.5-pro). - Configures advanced model settings based on the API request (
temperature,top_p, etc.) and application configuration (EnableWebSearch, etc.). - Pastes the user's prompt into the input area.
- Clicks the "Run" button and waits for the model to generate a response.
- Copies the markdown-formatted response from the UI.
- Transforms the response into the OpenAI ChatCompletion or ChatCompletionStream format and sends it back to the client.
- .NET 8.0 SDK
- Google Chrome browser
Edit the AIStudio2OpenAI/appsettings.json file to match your setup.
{"ChromeAutomation":{"ExecutablePath": null, // your Chrome.exe executable path"UserDataDir": null, // a empty folder to store chrome data"DebuggingPort": 9222, "MaxAccounts": 1// maximum number of Google accounts you logged in }, "Gemini":{"SetMaxThinkingTokens": true, "EnableCodeExecution": false, "EnableWebSearch": false }, "Kestrel":{"Endpoints":{"Http":{"Url": "http://localhost:3060" } } } }You must launch a dedicated Chrome instance for the adapter to connect to. Close all other Chrome instances first.
On Windows (Command Prompt):
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="C:\Users\%USERNAME%\Documents\ChromeAgent"On macOS (Terminal):
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir="$HOME/Documents/ChromeAgent"In the newly opened Chrome window, log in to your Google Account(s). If using multiple accounts, log them all in.
Once Chrome is running and you are logged in, open a separate terminal and run the application:
cd AIStudio2OpenAI dotnet runThe application will prompt you to press [Enter] to confirm Chrome is ready.
You can now send requests to http://localhost:3060 using any OpenAI-compatible client.
Example using curl:
curl http://localhost:3060/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-1.5-pro", "messages": [{ "role": "user", "content": "Write a short story about a robot who learns to paint." } ], "temperature": 0.7, "max_tokens": 256 }'This project is licensed under the MIT License. See the LICENSE file for details.