1
0
Fork 0
No description
Find a file
2026-03-02 21:14:20 +03:00
src refactor!: a lot of stuff 2026-03-02 21:14:20 +03:00
tests refactor!: a lot of stuff 2026-03-02 21:14:20 +03:00
.env.example refactor: add staged next-account rotation and clarify ChatGPT config 2026-03-02 10:58:20 +03:00
.gitignore refactor!: change the entire purpose of this script 2026-03-01 19:32:10 +03:00
Dockerfile refactor: harden ChatGPT token lifecycle with startup recovery, single-writer locking, and faster auth flow 2026-03-01 20:58:24 +03:00
entrypoint.sh refactor: harden ChatGPT token lifecycle with startup recovery, single-writer locking, and faster auth flow 2026-03-01 20:58:24 +03:00
pyproject.toml refactor!: a lot of stuff 2026-03-02 21:14:20 +03:00
README.md refactor!: a lot of stuff 2026-03-02 21:14:20 +03:00
uv.lock refactor!: change the entire purpose of this script 2026-03-01 19:32:10 +03:00

megapt

Service for issuing ChatGPT OAuth tokens via browser automation with disposable email.

Endpoints

  • GET /chatgpt/token
  • GET /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 prepare next_account (default: 85)
  • CHATGPT_SWITCH_THRESHOLD - usage threshold to switch active account to next_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:

  1. If active token is valid, service returns it immediately.
  2. If active token is expired, service tries refresh under a single write lock.
  3. If refresh fails or token is missing, service registers a new account (up to 4 attempts).
  4. When usage reaches CHATGPT_PREPARE_THRESHOLD, service prepares next_account.
  5. When usage reaches CHATGPT_SWITCH_THRESHOLD, service switches active account to next_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 with active and next_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.sh starts Xvfb and runs server.py.