https://github.com/mrshibly/phantomapi
๐ป PhantomAPI โ Turn ChatGPT's free web interface into an OpenAI-compatible API. Built with FastAPI + Playwright. Drop-in replacement for n8n, AI Agents, and any OpenAI client. Zero API costs.
https://github.com/mrshibly/phantomapi
ai-agent automation chatgpt chatgpt-proxy fastapi free-api n8n openai-api openai-compatible phantomapi playwright proxy python self-hosted
Last synced: about 2 months ago
JSON representation
๐ป PhantomAPI โ Turn ChatGPT's free web interface into an OpenAI-compatible API. Built with FastAPI + Playwright. Drop-in replacement for n8n, AI Agents, and any OpenAI client. Zero API costs.
- Host: GitHub
- URL: https://github.com/mrshibly/phantomapi
- Owner: mrshibly
- License: mit
- Created: 2026-03-28T16:56:48.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-03-28T18:00:38.000Z (3 months ago)
- Last Synced: 2026-03-28T19:28:47.538Z (3 months ago)
- Topics: ai-agent, automation, chatgpt, chatgpt-proxy, fastapi, free-api, n8n, openai-api, openai-compatible, phantomapi, playwright, proxy, python, self-hosted
- Language: Python
- Homepage:
- Size: 2.28 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ป PhantomAPI
### Turn ChatGPT into a FREE OpenAI-Compatible API
[](https://fastapi.tiangolo.com/)
[](https://playwright.dev/)
[](https://docker.com/)
[](LICENSE)
**The invisible proxy that bridges ChatGPT's free web interface with your AI automation workflows.**
[Quick Start](#-quick-start) ยท [n8n Integration](#-connecting-to-n8n) ยท [Architecture](#-architecture) ยท [Docker](#-docker-deployment)
---
## ๐ What is PhantomAPI?
**PhantomAPI** is a high-performance proxy server that makes ChatGPT's free web interface behave like the official OpenAI API. It's designed as a **drop-in replacement** for any tool that speaks the OpenAI protocol โ especially **n8n**.
### โจ Key Features
| Feature | Description |
|:---|:---|
| ๐ธ **Zero API Costs** | Uses ChatGPT's free web interface via headless browser automation |
| โก **Async Architecture** | Built on FastAPI with a dedicated browser thread for non-blocking requests |
| ๐ค **AI Agent Support** | Full tool-calling / function-calling support for n8n Agent nodes |
| ๐ **API Key Auth** | Protected with Bearer token authentication |
| ๐ณ **Docker Ready** | Deploy in seconds with `docker-compose up` |
| ๐จ **Built-in GUI** | A sleek dark-mode chat interface for quick testing |
| ๐ **Clean Architecture** | Proper FastAPI structure โ routers, schemas, services, utils |
---
## โ๏ธ How It Works
```
โโโโโโโโโโโโ HTTP/JSON โโโโโโโโโโโโโโโโ Playwright โโโโโโโโโโโโโโโโ
โ n8n โ โโโโโโโโโโโโโโโโโโโถ โ PhantomAPI โ โโโโโโโโโโโโโโโโโโโถ โ ChatGPT โ
โ (or any โ โโโโโโโโโโโโโโโโโโโ โ (FastAPI) โ โโโโโโโโโโโโโโโโโโโ โ (Web UI) โ
โ client) โ OpenAI Schema โ โ Scrape Response โ โ
โโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
```
1. **You send** a standard OpenAI API request to PhantomAPI
2. **PhantomAPI** formats your messages into a prompt and types it into ChatGPT's web interface using a stealth browser
3. **ChatGPT responds** on the web page โ PhantomAPI scrapes the text
4. **The response** is formatted back into the official OpenAI JSON schema and returned to you
---
## ๐ ๏ธ Quick Start
### Prerequisites
- **Python 3.10+**
- **Google Chrome** installed on your system
### 1. Clone & Install
```bash
git clone https://github.com/mrshibly/phantom-api.git
cd phantom-api
pip install -r requirements.txt
python -m playwright install chromium
```
### 2. Configure
```bash
cp .env.example .env
# Edit .env and set your API_SECRET_KEY
```
### 3. Run
```bash
python run.py
```
The server will start on `http://localhost:7777`.
| Endpoint | Description |
|:---|:---|
| `http://localhost:7777/` | Health check |
| `http://localhost:7777/docs` | Swagger UI (interactive API docs) |
| `http://localhost:7777/gui` | Chat GUI for quick testing |
---
## ๐ Connecting to n8n
### Method 1: OpenAI Node (Recommended)
1. In n8n, go to **Credentials โ New โ OpenAI API**
2. Set **Base URL** to: `http://127.0.0.1:7777/v1`
3. Set **API Key** to your `API_SECRET_KEY` from `.env`
4. Use this credential in any **OpenAI** or **AI Agent** node
> **Docker Tip:** If n8n runs in Docker, use `http://host.docker.internal:7777/v1`
### Method 2: HTTP Request Node
1. Add an **HTTP Request** node
2. **Method:** `POST`
3. **URL:** `http://127.0.0.1:7777/v1/chat/completions`
4. **Authentication:** Header Auth โ `Authorization: Bearer YOUR_KEY`
5. **Body (JSON):**
```json
{
"model": "gpt-4o-mini",
"messages": [
{ "role": "user", "content": "Hello, PhantomAPI!" }
]
}
```
---
## ๐ Architecture
```
phantom-api/
โโโ app/
โ โโโ main.py # App factory, CORS, lifespan
โ โโโ config.py # Environment-driven settings
โ โโโ dependencies.py # Auth dependency injection
โ โโโ api/v1/
โ โ โโโ router.py # Route aggregator
โ โ โโโ chat.py # POST /v1/chat/completions
โ โ โโโ responses.py # POST /v1/responses
โ โ โโโ models.py # GET /v1/models
โ โโโ schemas/
โ โ โโโ chat.py # Request/Response models
โ โ โโโ responses.py # Responses API models
โ โโโ services/
โ โ โโโ browser.py # Playwright browser engine
โ โโโ utils/
โ โโโ prompt.py # Smart prompt builder
โ โโโ parser.py # Tool-call JSON parser
โโโ static/
โ โโโ index.html # Chat GUI
โโโ tests/
โ โโโ test_health.py # Endpoint tests
โโโ Dockerfile
โโโ docker-compose.yml
โโโ requirements.txt
โโโ .env.example
โโโ run.py # Entry point
```
---
## ๐ณ Docker Deployment
```bash
# Build and run
docker-compose up --build -d
# The server is now running on http://localhost:7777
```
---
## ๐ง API Reference
### `POST /v1/chat/completions`
Standard OpenAI Chat Completions endpoint. Supports messages, tools, and function calling.
### `POST /v1/responses`
Modern Responses API for newer n8n versions. Accepts `input` (string or messages) and optional `instructions`.
### `GET /v1/models`
Returns available model identifiers (used by n8n's model dropdown).
### `GET /`
Health check โ returns server status and version.
---
## ๐ License
This project is open-sourced under the [MIT License](LICENSE).
---
**Built with โค๏ธ by [mrshibly](https://github.com/mrshibly)**