What This Project Does
codex-quota is a lightweight tool for checking ChatGPT Codex quota usage, with data fetched from https://chatgpt.com/backend-api/wham/usage.
Main features:
- Supports both single-account and multi-account queries (
account/*.auth.json). - Outputs
five_hour%,weekly%,weekly_reset, and marks the source (networkorcache). - Uses exponential backoff retries for temporary failures (
408,429,5xx). - Includes local caching to reduce repeated requests when quota is already exhausted.
- Provides a Web Dashboard, JSON API, and auth file management pages.
Advantages:
- Lightweight: runs with simple scripts and minimal dependencies.
- Practical: supports both CLI and Web entry points.
- Deployable: works with Docker and Docker Compose.
- Easy to operate: includes retry, cache, and scheduled refresh support.
Prepare Account Credentials First
Create credential files in account/<name>.auth.json, for example:
|
|
Explanation:
access_tokenandaccount_idare required by the usage API.<name>in the filename is used as the account name in output.
Local CLI Usage (Keep Original Commands)
Install dependencies:
|
|
Explanation: installs project dependencies.
Query all accounts:
|
|
Explanation: reads account/*.auth.json and outputs quota summary for all accounts.
Query one account:
|
|
Explanation: only queries account/your_account_name.auth.json.
Force refresh (skip cache):
|
|
Explanation: ignores local cache and fetches fresh data directly.
CLI Options (Aligned with README)
account_name: optional account name (without.auth.json).--account-dir: auth directory, defaultaccount.--chatgpt-url: quota API endpoint.--raw-json: print full JSON response body.--raw-headers: print response headers.--refresh: ignore cache.--retries: retry count, default3.--retry-delay: base retry delay in seconds, default2.0.
Web Dashboard Usage (Keep Original Command)
Start the service:
|
|
Explanation: starts HTTP service listening on port 8081.
Access URL: http://localhost:8081
Service options:
--host: bind address, default0.0.0.0.--port: service port, default8081.--interval-seconds: scheduled refresh interval, default3600.--account-dir: auth directory, defaultaccount.--state-file: state file path, default<account-dir>/codex_quota_web_results.json.--account-name: optional single-account mode.--chatgpt-url: quota API endpoint.--retries: retry count.--retry-delay: base retry delay.--refresh: ignore CLI cache during scheduled runs.
HTTP Endpoints (For Automation)
GET /: dashboard page.GET /api/results: latest results in JSON.GET /refresh: trigger immediate refresh and redirect to/.GET /auth: list auth files.GET /auth/new: form to create auth file.GET /auth/edit?name=<account>: form to edit auth file.POST /auth/save: create/update auth file.POST /auth/delete: delete auth file.
Docker Usage (Keep Original Commands)
Build image:
|
|
Explanation: builds the current project as image codex-quota.
Run container (map 8081):
|
|
Explanation:
--rm: remove container automatically after exit.-p 8081:8081: map host port to container port.-v ./account:/app/account: mount local credentials into container.
Access URL: http://localhost:8081
Docker Compose Usage (Keep Original Command)
Start:
|
|
Explanation: build and start services based on docker-compose.yml.
Access URL: http://localhost:8081
Usage Tips
- For multi-account scenarios, use Dashboard first for unified view and auth management.
- For alerting or automation, prefer
GET /api/results. - Do not commit real
access_tokenvalues to public repositories. - If you see many temporary failures, increase
--retriesand--retry-delay.