Skip to content

Commit b5e5d63

Browse files
committed
fix(codex): correct quota tracking error mapping
Update parse_quota_error to correctly identify Codex API's structured usage limit reached errors ('type': 'usage_limit_reached') so the rotation client correctly applies cooldowns during quota exhaustion events.
1 parent dcb132d commit b5e5d63

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/rotator_library/providers/codex_provider.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ def parse_quota_error(
13431343
error_data = json.loads(error_body)
13441344
error_info = error_data.get("error", {})
13451345

1346-
if error_info.get("code") == "rate_limit_exceeded":
1346+
if error_info.get("code") == "rate_limit_exceeded" or error_info.get("type") == "rate_limit_exceeded":
13471347
# Look for retry-after information
13481348
message = error_info.get("message", "")
13491349
retry_after = 60 # Default
@@ -1361,12 +1361,19 @@ def parse_quota_error(
13611361
"quota_reset_timestamp": None,
13621362
}
13631363

1364-
if error_info.get("code") == "quota_exceeded":
1364+
if error_info.get("code") == "quota_exceeded" or error_info.get("type") == "usage_limit_reached":
1365+
reset_at = error_info.get("resets_at")
1366+
resets_in = error_info.get("resets_in_seconds")
1367+
1368+
retry_after = 3600
1369+
if resets_in:
1370+
retry_after = resets_in
1371+
13651372
return {
1366-
"retry_after": 3600, # 1 hour default
1373+
"retry_after": retry_after,
13671374
"reason": "QUOTA_EXHAUSTED",
13681375
"reset_timestamp": None,
1369-
"quota_reset_timestamp": None,
1376+
"quota_reset_timestamp": reset_at,
13701377
}
13711378

13721379
except Exception:

0 commit comments

Comments
 (0)