Created
June 27, 2026 10:44
-
-
Save majd/0e8d80e6b0afc5cf684c312b76bf86c8 to your computer and use it in GitHub Desktop.
Codex Resets Summary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import json | |
| import urllib.request | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| AUTH = Path("~/.codex/auth.json").expanduser() | |
| URL = "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits" | |
| def headers(): | |
| tokens = json.loads(AUTH.read_text())["tokens"] | |
| return { | |
| "Authorization": f"Bearer {tokens['access_token']}", | |
| "ChatGPT-Account-ID": tokens["account_id"], | |
| "originator": "Codex Desktop", | |
| "User-Agent": "codex-resets/1.0", | |
| } | |
| def fetch(): | |
| request = urllib.request.Request(URL, headers=headers()) | |
| with urllib.request.urlopen(request, timeout=25) as response: | |
| return json.loads(response.read()) | |
| def as_datetime(value): | |
| if isinstance(value, (int, float)) or str(value).isdigit(): | |
| seconds = float(value) | |
| if seconds > 10_000_000_000: | |
| seconds /= 1000 | |
| return datetime.fromtimestamp(seconds, timezone.utc) | |
| return datetime.fromisoformat(str(value).replace("Z", "+00:00")) | |
| def local_time(value): | |
| return as_datetime(value).astimezone().strftime("%Y-%m-%d %H:%M:%S %Z") | |
| def remaining(value): | |
| seconds = int((as_datetime(value) - datetime.now(timezone.utc)).total_seconds()) | |
| if seconds < 0: | |
| return "expired" | |
| days, seconds = divmod(seconds, 86_400) | |
| hours, seconds = divmod(seconds, 3_600) | |
| minutes, _ = divmod(seconds, 60) | |
| parts = [f"{days}d"] if days else [] | |
| if hours: | |
| parts.append(f"{hours}h") | |
| if minutes and len(parts) < 2: | |
| parts.append(f"{minutes}m") | |
| return " ".join(parts[:2]) or "under 1m" | |
| data = fetch() | |
| credits = [c for c in data.get("credits", []) if c.get("status") == "available"] | |
| print(f"Available Codex resets: {data.get('available_count', len(credits))}") | |
| for i, credit in enumerate(credits, 1): | |
| expires = credit["expires_at"] | |
| print(f"{i}. expires {local_time(expires)} ({remaining(expires)})") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment