# WebAI2API

> A self-hosted server that drives web AI chat sites like LMArena and Gemini in Camoufox browser windows and exposes them as an OpenAI-compatible API

- Category: Evaluation & Production Ops / Gateways & Routing
- Language: JavaScript
- Licence: MIT
- Repository: https://github.com/foxhui/WebAI2API
- Website: https://foxhui.github.io/WebAI2API/
- Canonical page: https://ai-tldr.dev/tools/webai2api/

## In short

WebAI2API is a self-hosted server that drives web AI chat sites like LMArena and Gemini in Camoufox browser windows and exposes them as an OpenAI-compatible API. The README says it simulates human typing and mouse movement and uses feature camouflage to avoid automation detection. It sits in the Gateways & Routing category of the Evaluation & Production Ops tools and is open-source, written in JavaScript and licensed MIT.

## Overview

WebAI2API is an open-source Node.js server, released under the MIT license, that turns web-based AI chat services into a general API. Instead of calling a provider's official API, it opens the site in a Camoufox (Playwright) browser window that you have logged into yourself, types the prompt, waits for the answer and returns it through OpenAI-format endpoints: `POST /v1/chat/completions` with streaming, `GET /v1/models`, and `GET /v1/cookies` for reading the session cookies the browser keeps renewed. The README says it simulates human typing and mouse movement and uses feature camouflage to avoid automation detection.

The README's support table covers LMArena, Gemini Enterprise Business, Nano Banana Free, zAI, Google Gemini, ZenMux, ChatGPT, DeepSeek, Sora, Google Flow and Doubao, each marked for text, image or video generation; the example config also lists a Claude.ai text adapter. Each site is an adapter type. A browser instance is a separate Camoufox process with its own user-data directory (`userDataMark`) and optional per-instance proxy, so several accounts stay isolated; workers are tabs inside an instance, each bound to one adapter. A pool schedules requests across all workers (least busy, round robin or random), with a task queue, failover to another worker serving the same model, and retries. A `merge` worker lets one tab serve several backends.

A web admin UI on port 3000 shows system status and the task queue, edits server, worker-pool, browser and adapter settings, has an API test panel, a log viewer, and a virtual-display (VNC) view of the Xvfb browser windows on Linux and Docker, which is how you log in to each site the first time. The project carries an explicit disclaimer: it is for educational and exchange purposes only, the author is not responsible for consequences such as account suspension, and users should comply with the terms of service of the sites involved. The README also notes that requests are slow because they go through a real browser, that non-streaming requests are rejected once the backlog exceeds the configured limit, and recommends running headful (or under Xvfb) rather than headless, since headless mode may be detected.

## What it does

- OpenAI-compatible `/v1/chat/completions` (streaming with `:keepalive` heartbeats so queued requests do not time out), `/v1/models` and `/v1/cookies` endpoints, protected by a bearer token
- Adapters for LMArena, Google Gemini, Gemini Enterprise Business, ChatGPT, DeepSeek, Doubao, zAI, ZenMux, Nano Banana Free, Sora and Google Flow, covering text, image and video generation where each site offers it
- Multi-account isolation: each browser instance gets its own Camoufox user-data directory and its own proxy (the example config shows SOCKS5 with optional auth)
- Worker pool with least-busy, round-robin or random scheduling, a task queue, automatic failover and retries, plus `merge` workers that serve several backends from one tab
- Image input as Base64 data URLs (PNG, JPEG, GIF, WebP, up to 10 per request, fewer on some sites), converted to JPG before upload
- Web admin UI with dashboard, configuration and instance management, API tester, log viewer and an in-browser VNC view of the virtual display

## Getting started

Commands come from the project's README and deployment guide. WebAI2API needs Node.js 20 or later and runs on Windows, Linux and macOS; Camoufox is downloaded during setup. You need your own account on each site you want to use.

1. Install from source

   Clone the repo, install dependencies, then run `npm run init` to fetch the Camoufox browser and other precompiled pieces. That script downloads from GitHub; pass `-proxy` if your network needs one. On Linux, also install the virtual-display packages.

```bash
git clone https://github.com/foxhui/WebAI2API.git
cd WebAI2API
pnpm install
npm run init
# Linux only
apt install -y xvfb x11vnc libgtk-3-0 libx11-xcb1 libasound2
```

2. Or run it with Docker

   The image enables Xvfb and VNC by default and keeps its config and browser data in the mounted `data` folder. A `docker-compose.yaml` is in the repo for `docker compose up -d`.

```bash
docker run -d --name webai-2api \
  -p 3000:3000 \
  -v "$(pwd)/data:/app/data" \
  --shm-size=2gb \
  foxhui/webai-2api
```

3. Set the API token

   On first run `config.example.yaml` is copied to `data/config.yaml`. Change `auth` (it guards both the API and the web UI; `npm run genkey` generates one), configure instances and workers under `backend.pool`, and restart for changes to take effect.

```yaml
server:
  port: 3000
  auth: sk-change-me-to-your-secure-key
```

4. Start the server and log in to each site

   On Linux start it with a virtual display, open http://localhost:3000, connect in the Virtual Display section and log in to each AI site by hand, sending one message to clear any human verification. On Windows the browser window opens directly. The WebUI is unencrypted, so on a public server reach it through an SSH tunnel or HTTPS.

```bash
npm start -- -xvfb -vnc
# login mode: temporarily disables headless mode and automation
npm start -- -login -xvfb -vnc
# from your own machine, for a remote server
ssh -L 3000:127.0.0.1:3000 root@Server_IP
```

5. Call it like the OpenAI API

   List the models your configured adapters offer, then send a chat request. The README strongly recommends `stream: true`, which keeps the connection alive while the request waits in the queue.

```bash
curl http://localhost:3000/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"

curl http://localhost:3000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gemini-3-pro",
    "messages": [{"role": "user", "content": "Hello, please introduce yourself"}],
    "stream": true
  }'
```

## When to use it

- Reach for it to point an OpenAI-compatible client or script at a chat site you already use through its web interface, such as LMArena or Gemini
- Reach for it to run image or video generation offered on sites like Gemini, ChatGPT or Sora from your own code through one endpoint
- Reach for it to spread requests over several of your own logged-in accounts, each in an isolated browser profile behind its own proxy
- Reach for it to export the session cookies a long-running browser keeps fresh, for use with other tools
