sub2api icon indicating copy to clipboard operation
sub2api copied to clipboard

Anthropic 429 window reset can be shortened by temp unschedulable rules

Open WesleyZiwen opened this issue 5 months ago • 0 comments

Problem

Anthropic/Claude official 429 responses can include per-window reset headers for the unified 5h and 7d rate-limit windows, for example:

  • anthropic-ratelimit-unified-5h-reset
  • anthropic-ratelimit-unified-5h-utilization
  • anthropic-ratelimit-unified-5h-surpassed-threshold
  • anthropic-ratelimit-unified-5h-status
  • anthropic-ratelimit-unified-7d-reset
  • anthropic-ratelimit-unified-7d-utilization
  • anthropic-ratelimit-unified-7d-surpassed-threshold

Those headers describe the real account-level cooldown window. However, if an account also has a broad temp_unschedulable_rules rule for HTTP 429 messages such as rate limit, the local temporary-unschedulable rule can handle the response first.

In that case, a real multi-hour or multi-day Anthropic window can be shortened to a local temporary pause, such as 10 minutes. After that local pause expires, the scheduler may send traffic to the same account again while the official Anthropic window is still exhausted.

Expected behavior

When an Anthropic account returns an official 429 with an exhausted 5h or 7d window and a valid reset timestamp, Sub2API should persist the official reset time as the account rate-limit cooldown before applying user-configured temporary-unschedulable rules.

The official window cooldown should not be shortened by a local keyword-based temporary-unschedulable rule.

Proposed fix

  • Detect Anthropic 429 responses with official 5h / 7d window exhaustion signals.
  • Prefer the 7d reset when both 5h and 7d are exhausted.
  • Persist the selected reset time through SetRateLimited.
  • Keep an existing active cooldown if it is already later than the observed reset time.
  • Fall back to the existing temporary-unschedulable behavior when no official exhausted window can be identified.

Validation

A focused regression test can cover an Anthropic 429 response that includes an exhausted 5h window while the account also has a matching temp_unschedulable_rules rule. The expected result is:

  • SetRateLimited is called with the official 5h reset timestamp.
  • SetTempUnschedulable is not called for that response.

Fixed behavior example

After applying the proposed fix, an account that receives an official Anthropic/Claude window 429 remains rate-limited and is excluded from scheduling until the official reset time. The admin UI shows the account as not participating in scheduling and displays the expected automatic recovery time.

Anthropic Claude account rate-limited until official reset time

WesleyZiwen avatar Jun 12 '26 05:06 WesleyZiwen