Codex Chat is an internal-first GPT-style web app backed by the Codex CLI. It provides a browser chat UI, login-gated access, persistent chat history, and a server-side bridge that can run Codex sessions for each user.
This repository contains the FastAPI backend, a lightweight static frontend, and deployment templates.
- FastAPI backend with JSON API.
- Static browser chat UI served by the backend.
- Login-gated internal preview mode.
- Admin user management endpoints.
- Persistent users, tokens, and chat history in local JSON storage.
- Codex CLI bridge with resumable thread/session state.
- Optional per-user Linux sandbox provisioning.
- Optional Sub2API integration for user quota/concurrency management.
- Optional LLM Web API agent integration.
- Deployment templates for systemd and Nginx.
.
├── app/
│ ├── config.py
│ ├── codex_runner.py
│ ├── llm_web_agent.py
│ ├── main.py
│ ├── models.py
│ ├── store.py
│ └── sub2api_client.py
├── frontend/
│ ├── index.html
│ ├── styles.css
│ └── app.js
├── deploy/
├── scripts/
├── .env.example
├── requirements.txt
└── run.py
Runtime directories are intentionally ignored:
.envstorage/workspaces/tools/.playwright-mcp/test-results/nextchat/
- Python 3.11+
- Codex CLI
- Optional: Nginx and systemd for production deployment
Create and activate a virtual environment:
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txtCreate local configuration:
cp .env.example .envEdit .env and set at least:
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=change-me-now
CODEX_BIN=codex
CODEX_MODEL=
Start the app:
python run.pyOpen:
http://127.0.0.1:8787
Important settings:
INTERNAL_ONLY=true
ALLOW_PUBLIC_SIGNUP=false
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=change-me-now
CODEX_BIN=codex
CODEX_WORKSPACE_ROOT=./workspaces
STORAGE_DIR=./storage
For a simple local demo, keep:
CODEX_RUN_AS_LINUX_USER=false
For a multi-user server deployment, review deploy/DEPLOY.md and
scripts/provision-linux-users.sh before enabling per-user Linux sandboxes.
Common endpoints:
GET /api/configPOST /api/auth/loginPOST /api/auth/logoutGET /api/meGET /api/chat/sessionsPOST /api/chat/sessionsGET /api/chat/sessions/{session_id}POST /api/chat/sessions/{session_id}/messagesGET /api/admin/usersPATCH /api/admin/users/{user_id}
The frontend uses bearer tokens returned by /api/auth/login.
Production deployment templates live in deploy/:
deploy/codex-chat.servicedeploy/nginx.example.conf
The deployment guide is in:
deploy/DEPLOY.md
Before using the templates on another machine, replace hardcoded paths, service users, and domains with your own values.
The backend keeps the implementation intentionally small and file-based. This is useful for internal previews, but a public deployment should replace JSON storage with a real database, add stronger audit logging, and harden user isolation.