No description
| src | ||
| tests | ||
| .env.example | ||
| .gitignore | ||
| Dockerfile | ||
| entrypoint.sh | ||
| pyproject.toml | ||
| README.md | ||
| uv.lock | ||
megapt
Service for issuing ChatGPT OAuth tokens via browser automation with disposable email.
Endpoints
GET /chatgpt/tokenGET /token(legacy alias, same as chatgpt)
Response shape:
{
"token": "...",
"limit": {
"used_percent": 0,
"remaining_percent": 100,
"exhausted": false,
"needs_prepare": false
},
"usage": {
"primary_window": {
"used_percent": 0,
"limit_window_seconds": 604800,
"reset_after_seconds": 604800,
"reset_at": 1772987784
},
"secondary_window": null
}
}
Environment Variables
PORT- HTTP server port (default:8080)DATA_DIR- persistent data directory for tokens/screenshots (default:./data)CHATGPT_PREPARE_THRESHOLD- usage threshold to preparenext_account(default:85)CHATGPT_SWITCH_THRESHOLD- usage threshold to switch active account tonext_account(default:95)
Example config is in .env.example.
Token Lifecycle
- active account - currently served token.
- next account - pre-created account/token stored for fast switch.
Behavior:
- If active token is valid, service returns it immediately.
- If active token is expired, service tries refresh under a single write lock.
- If refresh fails or token is missing, service registers a new account (up to 4 attempts).
- When usage reaches
CHATGPT_PREPARE_THRESHOLD, service preparesnext_account. - When usage reaches
CHATGPT_SWITCH_THRESHOLD, service switches active account tonext_account.
Startup Behavior
On startup, service ensures active token exists and is usable. Standby preparation runs through provider lifecycle hooks/background trigger when needed.
Data Files
DATA_DIR/chatgpt_tokens.json- token state withactiveandnext_account.DATA_DIR/screenshots/- automation failure screenshots.
Run Locally
PYTHONPATH=./src python src/server.py
Unit Tests
The project has unit tests only (no integration/network tests).
pytest -q
Docker Notes
- Dockerfile sets
DATA_DIR=/data. entrypoint.shstarts Xvfb and runsserver.py.