1
0
Fork 0
gibidy/README.md

87 lines
2.3 KiB
Markdown

# 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:
```json
{
"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`.
## Disposable Email Provider
- Default provider is `mail.tm` API (`MailTmProvider`) and does not use browser automation.
- Flow: fetch domains -> create account with random address/password -> get JWT token -> poll messages.
## 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
```bash
PYTHONPATH=./src python src/server.py
```
## Unit Tests
The project has unit tests only (no integration/network tests).
```bash
pytest -q
```
## Docker Notes
- Dockerfile sets `DATA_DIR=/data`.
- `entrypoint.sh` starts Xvfb and runs `server.py`.