[亲测有效] Codex 赠送的重置机会,有效期查询方法

LonelyM 2026-06-29 11:31 1

🚀教大家一个方法,查询 Codex 赠送的重置机会什么时候到期!


方法很简单,将下面的提示词发送给 Codex 即可。


========🔥提示词==========


请使用本机 Codex 凭证查一下 rate-limit reset credits:


读取 ~/.codex/auth.json 里的 tokens.access_token ,请求接口:
https://chatgpt.com/backend-api/wham/rate-limit-reset-credits


要求:



  1. 不要打印 access_token 、refresh_token 、cookie 或完整唯一 ID

  2. 只汇总 available_count 、每个 credit 的 status/title/granted_at/expires_at

  3. 把 granted_at/expires_at 从 UTC 转成本地时间

  4. 如果状态码返回 401 ,说明是凭证失效或没带对 Authorization header


========🔥提示词==========

最新回复 (12)
  • plmsuper8 06-29 11:54
    1
    或者这个:
    ```
    python3 - <<'PY'
    import json
    import os
    import urllib.request
    from datetime import datetime, timezone

    AUTH_PATH = os.path.expanduser("~/.codex/auth.json")
    URL = "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits"

    def to_local_time(value):
    if not value:
    return None
    try:
    if isinstance(value, (int, float)):
    # 兼容秒或毫秒时间戳
    if value > 10_000_000_000:
    value = value / 1000
    dt = datetime.fromtimestamp(value, tz=timezone.utc)
    else:
    s = str(value).replace("Z", "+00:00")
    dt = datetime.fromisoformat(s)
    if dt.tzinfo is None:
    dt = dt.replace(tzinfo=timezone.utc)
    return dt.astimezone().strftime("%Y-%m-%d %H:%M:%S %Z")
    except Exception:
    return value

    with open(AUTH_PATH, "r", encoding="utf-8") as f:
    auth = json.load(f)

    token = auth.get("tokens", {}).get("access_token")
    if not token:
    raise SystemExit("未找到 tokens.access_token")

    req = urllib.request.Request(
    URL,
    headers={
    "Authorization": f"Bearer {token}",
    "Accept": "application/json",
    },
    method="GET",
    )

    try:
    with urllib.request.urlopen(req, timeout=20) as resp:
    status = resp.status
    body = resp.read().decode("utf-8")
    except urllib.error.HTTPError as e:
    status = e.code
    body = e.read().decode("utf-8", errors="replace")

    if status == 401:
    print("HTTP 401:凭证失效,或请求没有带正确的 Authorization header")
    raise SystemExit(1)

    if status < 200 or status >= 300:
    print(f"HTTP {status}")
    print("请求失败;未输出敏感信息。")
    raise SystemExit(1)

    data = json.loads(body)

    available_count = data.get("available_count")
    credits = data.get("credits", [])

    print("available_count:", available_count)
    print()

    for i, c in enumerate(credits, 1):
    print(f"credit #{i}")
    print(" status:", c.get("status"))
    print(" title:", c.get("title"))
    print(" granted_at:", to_local_time(c.get("granted_at")))
    print(" expires_at:", to_local_time(c.get("expires_at")))
    PY
    ```
  • unusualcat 06-29 12:03
    2
    试了,确实可以查询到每个 reset 的获得时间和过期时间。
  • zls3201 06-29 12:57
    3
    cpa 不是自带么 搞这么麻烦
  • littlefishzzz 06-29 15:09
    4
    @zls3201 问一下 codex 不是就行么 cpa 搞这么麻烦
  • tylearymf 06-29 15:16
    5
    可以,很强👍
  • Dream4U 06-29 15:18
    6
    @zls3201 codex 自带
  • zls3201 06-29 17:12
    7
    @Dream4U 我用的 codex cli + pi
  • zls3201 06-29 17:13
    8
    @littlefishzzz 我用的 codex cli + pi
  • Jiannanzzz 06-29 17:20
    9
    我一直用的 omp,我的 /usage 就可以显示
  • bailywen 06-29 19:36
    10
    cpa 或者 codex 不都是有默认显示吗?为什么重复造?
  • 1874w 06-30 05:09
    11
    @zls3201 #3 你要笑死我哈哈哈哈哈,这哪麻烦了?就算是新电脑装个 codex CLI ,也就是一句提示词的事。还安装什么 PI 搞这么麻烦[旺柴]
  • zls3201 06-30 07:32
    12
    @1874w 你说的都对
* 帖子来源V2EX
返回