Skip to content

feat(auth): support Codex rate limit reset credits in quota inspection and consumption - #475

Merged
SaladDay merged 1 commit into
SaladDay:mainfrom
bytemain:feat/codex-rate-limit-reset-credits
Sep 29, 2026
Merged

SaladDay merged 1 commit into
SaladDay:mainfrom
bytemain:feat/codex-rate-limit-reset-credits

Conversation

@bytemain

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for querying and redeeming OpenAI / Codex server-side Rate Limit Reset Credits (Banked Resets) in cc-switch.

Background & Motivation

ChatGPT Pro and selected Team accounts receive periodic Rate Limit Reset Credits (Banked Resets) when hitting rate limit windows. Previously, users had to log into the web interface or run custom scripts to check or redeem reset credits. This change allows users to view available reset credits directly during quota inspection and safely redeem them via the CLI.

Features

  1. Reset Credits Querying:

    • Fetches available reset credits from GET https://chatgpt.com/backend-api/wham/rate-limit-reset-credits during Codex quota inspection.
    • Filters and validates credits fail-closed (reset_type == "codex_rate_limits", status == "available", is_supported_by_plan == true, non-empty granted_at).
    • Sorts available credits by earliest expires_at so the optimal card is queued first.
    • Displays credit summary and card lists in cc-switch provider quota <id> and JSON outputs.
  2. Safe Consumption Flow:

    • Dry-run by default: Calling without --confirm displays target credit metadata, expiration, available card count, and a warning that consumption is permanent and irreversible.
    • Mandatory --confirm flag required to execute consumption against POST https://chatgpt.com/backend-api/wham/rate-limit-reset-credits/consume.
    • Supports selecting a specific credit ID (--credit-id <id>) or defaults to the earliest expiring credit.
    • Treats upstream code: "reset" and code: "already_redeemed" as success.
    • Re-inspects quota immediately after redemption to report updated utilization tiers and remaining cards.
  3. CLI Interfaces:

    • cc-switch auth reset-quota [--account-id <id>] [--credit-id <id>] [--confirm] [--json]
    • cc-switch provider quota <provider-id> --reset [--credit-id <id>] [--confirm] [--json]

Testing

  • Added unit tests for filtering & sorting reset credits (filter_and_sort_codex_reset_credits_applies_strict_rules).
  • Added unit tests for deserializing reset credits in usage responses (parse_codex_usage_with_reset_credits).
  • Added CLI parsing tests for auth reset-quota and provider quota --reset.
  • Ran test suites:
    • cargo +1.91.1 test --lib services::subscription::tests (13 passed)
    • cargo +1.91.1 test --lib cli::tests (110 passed)
    • cargo +1.91.1 test --lib cli::commands::provider_inspect::tests (21 passed)
    • cargo +1.91.1 check --bin cc-switch (clean, 0 errors)

…n and consumption

- Query available rate limit reset credits from ChatGPT backend API during quota inspection
- Integrate reset credits display into both textual and JSON provider/auth quota outputs
- Add fail-closed redemption flow with dry-run default and mandatory --confirm safety gate
- Add 'cc-switch auth reset-quota' subcommand and 'cc-switch provider quota <id> --reset' flag
- Automatically select earliest expiring credit when credit_id is not specified
- Re-inspect quota immediately upon successful redemption following CPA-Helper keeper rules
@SaladDay

Copy link
Copy Markdown
Owner

LGTM, THANKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants