OpenAI-compatible local API bridge powered by ChatGPT Web browser automation.
Built by deco31416.com for local experiments, agent workflows, IDE integrations, and controlled automation.
ChatGPT Web Bridge is a local FastAPI server that exposes an OpenAI-compatible interface, including:
GET /v1/modelsPOST /v1/chat/completionsGET /health
Instead of calling the official OpenAI API directly, this bridge sends prompts to the ChatGPT Web UI through a controlled Playwright browser session.
In simple terms:
Your local tools talk to this server as if it were an OpenAI API. This server opens ChatGPT Web in a browser, sends the message, reads the answer, and returns it in OpenAI-compatible JSON format.
"El sistema me conoce, aprende conmigo y me ayuda a no repetirme. Mi experiencia queda encapsulada en archivos que solo yo poseo. Si cambio de máquina, me llevo mi carpeta y listo. El repo solo tiene la semilla; el árbol crece en mi jardín."
This project is experimental software.
It depends on browser automation and the ChatGPT Web interface, which may change at any time. Selectors, page behavior, login requirements, rate limits, and response timing may break without notice.
This project is intended for:
- Local development
- Personal experimentation
- Internal tools
- IDE integrations
- Agent prototyping
It is not recommended for production, public deployment, resale as a hosted API, or high-volume automated usage.
- Overview
- Important Notice
- What It Does
- Architecture
- Project Structure
- Quick Start
- API Reference
- Configuration
- Client Integration
- Security Considerations
- Troubleshooting
- Roadmap
- Changelog
- Contributing
- License
ChatGPT Web Bridge allows local OpenAI-compatible clients to interact with ChatGPT Web through a browser session.
- OpenAI-compatible
/v1/chat/completions+/v1/modelsendpoints - Image support: upload images to ChatGPT Web, extract DALL-E generated images
- Model switching: auto-detect and switch models (GPT-4o, o3, o4-mini, GPT-4.1)
- Conversation tracking: persist chat IDs in
conversations.json(survives reboots) - Cost tracker: real token counting with
tiktoken+ USD cost per model - Per-chat analytics:
/v1/conversations/{id}/usagefor individual chat costs - Global usage:
/v1/usageaggregated token stats across all chats - Session persistence:
SessionStoresaves conversation metadata locally - Fast mode: instant typing via
fill()+ 300ms polling - Modular architecture: 13
.pyfiles, all under 200 lines - Playwright-based browser automation (headless or visible)
- Windows-friendly launch scripts (
run.ps1,run.bat) - MIT license © deco31416.com
Many tools, agents, IDE plugins, and local workflows expect an OpenAI-compatible API endpoint.
This project provides a local bridge so those tools can send requests to a browser-controlled ChatGPT Web session.
| Traditional API Flow | ChatGPT Web Bridge Flow |
|---|---|
| Client calls OpenAI API directly | Client calls local FastAPI server |
| Requires API key | Uses a logged-in ChatGPT Web session |
| Token billing through API | Uses your existing ChatGPT web access |
| Stable API contract | Experimental browser automation |
| Production-ready API behavior | Local experimental bridge |
sequenceDiagram
participant C as Client / IDE / Agent
participant S as FastAPI Server :9090
participant B as Playwright Bridge
participant W as ChatGPT Web
C->>S: POST /v1/chat/completions
S->>B: Send prompt
B->>W: Type message into ChatGPT Web
W-->>B: Generate response in browser
B->>W: Wait until response finishes
B-->>S: Extract assistant response
S-->>C: Return OpenAI-compatible JSON
idea-loca/
├── server.py # FastAPI app + lifecycle
├── routes.py # /v1/conversations + /v1/usage
├── chatgpt_bridge.py # Main orchestrator
├── browser.py # Playwright browser lifecycle
├── auth.py # Session detection
├── prompter.py # Type, send, wait for response
├── model_manager.py # Model detection + switching
├── image_handler.py # Image upload + DALL-E extraction
├── css_selectors.py # ChatGPT UI selectors
├── session_store.py # Conversation persistence (JSON)
├── cost_tracker.py # Token accumulation + USD cost
├── token_counter.py # tiktoken real token counting
├── models.py # Pydantic schemas
├── requirements.txt # Python dependencies
├── run.ps1 / run.bat # Windows launchers
├── .gitignore
├── CHANGELOG.md # Version history (ISO 8601)
├── CONTRIBUTING.md # Contribution guidelines
├── LICENSE # MIT - deco31416.com
└── README.md # Project documentation
- Python
3.11or higher - Windows, Linux, or macOS
- Google Chrome or Chromium
- Playwright
- A ChatGPT account
- Active ChatGPT Web session
cd idea-locapython -m venv .venv.venv\Scripts\Activate.ps1.venv\Scripts\activate.batsource .venv/bin/activatepip install -r requirements.txtplaywright install chromiumUse visible browser mode the first time so you can log in manually.
python server.py --port 9090 --no-headlessWhen the browser opens:
- Log into ChatGPT.
- Make sure the ChatGPT page loads correctly.
- Keep the browser session active.
- Test the API from another terminal.
After the login session is saved, you can run the bridge normally.
python server.py --port 9090Checks whether the local bridge is running and whether the ChatGPT session appears usable.
curl http://localhost:9090/health{
"status": "ok",
"authenticated": true,
"bridge": "chatgpt-web-bridge"
}Returns model identifiers in an OpenAI-compatible format.
curl http://localhost:9090/v1/models{
"object": "list",
"data": [
{
"id": "gpt-4o",
"object": "model",
"created": 1715367049,
"owned_by": "chatgpt-web"
},
{
"id": "gpt-4o-mini",
"object": "model",
"created": 1715367050,
"owned_by": "chatgpt-web"
},
{
"id": "o3",
"object": "model",
"created": 1735680000,
"owned_by": "chatgpt-web"
},
{
"id": "o4-mini",
"object": "model",
"created": 1735680001,
"owned_by": "chatgpt-web"
},
{
"id": "gpt-4.1",
"object": "model",
"created": 1740000000,
"owned_by": "chatgpt-web"
}
]
}Note: The requested model identifier is accepted for compatibility, but the actual response depends on the active ChatGPT Web session and selected/default model behavior.
OpenAI-compatible chat completions endpoint.
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Explain quantum computing in 3 sentences."
}
],
"temperature": 0.7
}{
"id": "chatcmpl-a1b2c3d4e5f6",
"object": "chat.completion",
"created": 1715367049,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Quantum computing uses qubits, which can represent more than just 0 or 1. This allows certain problems to be processed differently from classical computers. It is especially promising for optimization, simulation, and cryptography-related research."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 42,
"total_tokens": 50
}
}| Parameter | Type | Required | Behavior |
|---|---|---|---|
model |
string | Yes | Accepted for compatibility |
messages |
array | Yes | Last user message is sent to ChatGPT Web |
temperature |
number | No | Accepted for compatibility |
max_tokens |
number | No | Accepted for compatibility |
stream |
boolean | No | May be accepted depending on implementation |
| Header | Description |
|---|---|
X-Conversation-ID |
ChatGPT conversation UUID |
X-Conversation-URL |
Direct link to the chat (chatgpt.com/c/{id}) |
Lists all saved conversations with their token usage and metadata.
curl http://localhost:9090/v1/conversations{
"object": "list",
"data": [
{
"conversation_id": "a1b2c3d4...",
"model": "gpt-4o",
"url": "https://chatgpt.com/c/a1b2c3d4...",
"prompt_tokens": 2500,
"completion_tokens": 12000,
"total_tokens": 14500,
"last_used_at": 1715367100,
"summary": "Explícame Rust..."
}
]
}Per-chat token breakdown and estimated USD cost.
curl http://localhost:9090/v1/conversations/a1b2c3d4/usageGlobal accumulated token usage and cost across all chats.
curl http://localhost:9090/v1/usageRemove a saved conversation or reset the global usage counter.
| Argument | Default | Description |
|---|---|---|
--port |
9090 |
Local server port |
--host |
127.0.0.1 |
Host (0.0.0.0 para red local) |
--no-headless |
false |
Opens visible browser window for login/debug |
--api-key |
(env) | API key requerida en header X-API-Key |
Si habilitas --host 0.0.0.0, el puente queda accesible fuera de tu máquina.
Protección mínima recomendada:
- Define
BRIDGE_API_KEYen tu.env(copia.env.example). - Todas las peticiones deben incluir el header
X-API-Key. - Si tu key se ve comprometida, la cambias y reinicias. Fin del problema.
- No expongas el puente sin esta protección.
- Es bajo tu responsabilidad. El candado está puesto; si alguien lo rompe, cambias el candado.
"Si pierdo la llave, cambio la cerradura. Nadie se lleva mi jardín."
| Variable | Default | Description |
|---|---|---|
CHATGPT_URL |
https://chatgpt.com/ |
ChatGPT Web base URL |
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:9090/v1",
api_key="sk-local-no-key-required",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": "Hello from Python!"
}
],
)
print(response.choices[0].message.content)curl -s http://localhost:9090/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "What is 2 + 2?"
}
]
}' | python -m json.toolimport OpenAI from "openai";
const client = new OpenAI({
baseURL: "http://localhost:9090/v1",
apiKey: "sk-local-no-key-required",
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: "Hello from TypeScript!",
},
],
});
console.log(response.choices[0].message.content);{
"models": [
{
"title": "ChatGPT Web Bridge",
"provider": "openai",
"model": "gpt-4o",
"apiBase": "http://localhost:9090/v1",
"apiKey": "sk-local-no-key-required"
}
]
}This bridge controls a real browser session. Treat it as sensitive software.
| Risk | Recommendation |
|---|---|
| Exposing the server publicly | Bind only to localhost. Do not expose it to the internet. |
| Session hijacking | Protect the Playwright profile and browser session files. |
| Account abuse detection | Avoid high-volume automated requests. Add delays and rate limits. |
| UI selector changes | Keep the Playwright selectors updated. |
| Sensitive prompts | Do not send secrets, private keys, passwords, or production credentials. |
| Shared machines | Do not run with an authenticated ChatGPT session on untrusted computers. |
Do not deploy this as a public API service.
This project is not a replacement for the official OpenAI API. It is a local bridge for controlled personal or internal use.
Avoid:
- Public hosting
- Multi-user SaaS exposure
- Reverse proxying to the internet
- Selling hosted access
- High-frequency automation
- Sending confidential production data
| Symptom | Likely Cause | Suggested Fix |
|---|---|---|
Bridge no inicializado |
Browser bridge is not ready | Wait until the bridge initialization logs appear |
No se detectó sesión activa |
ChatGPT is not logged in | Run with --no-headless and log in manually |
Timeout |
ChatGPT Web is slow or rate-limited | Retry later or reduce request frequency |
No se encontró respuesta |
UI selectors changed | Update selectors in chatgpt_bridge.py |
| Import error | Missing dependencies | Run pip install -r requirements.txt |
| Browser does not open | Playwright browser missing | Run playwright install chromium |
| Client cannot connect | Wrong port or server not running | Confirm http://localhost:9090/health works |
After starting the server, run:
curl http://localhost:9090/healthThen test a completion:
curl -s http://localhost:9090/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"Say hello in one sentence."}]}'Planned improvements may include:
- Better request queue handling
- Local rate limiting
- More robust selector recovery
- Optional conversation isolation
- More complete OpenAI API compatibility
- Better streaming compatibility
- Structured error codes
- Better logging and diagnostics
See CHANGELOG.md for version history.
Contributions are welcome.
Before opening a pull request:
- Keep the project local-first.
- Avoid adding unnecessary complexity.
- Do not introduce unsafe public-exposure defaults.
- Keep code readable and easy to audit.
- Update documentation when behavior changes.
See CONTRIBUTING.md for more details.
MIT © deco31416.com
See LICENSE for the full license text.
This project is maintained under the deco31416.com name.
The MIT license allows use, modification, distribution, and sublicensing of the software, but it does not grant permission to misuse the deco31416.com name, identity, branding, domain, logos, or public reputation beyond required copyright and license attribution.
Made with ❤️ by deco31416.com
Experimental local bridge for ideas locas que funcionan.