Conversation
…, and browser headers - Reduce concurrent usage and metadata requests to prevent Cloudflare burst rate limiting - Add pacing/delays between account requests during batch refresh - Sequence usage updates and metadata updates instead of issuing them in parallel - Add single 750ms backoff and retry for transient 403 responses in usage and metadata endpoints - Update account_stats.rs to use browser user agent and standard browser headers - Provide a clear, actionable error message when Cloudflare rate limits requests
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When multiple accounts are refreshed on startup or via the refresh action, the application previously fired concurrent batches (up to 10 parallel requests) to both
chatgpt.com/backend-api/wham/usageandchatgpt.com/backend-api/accounts/check/v4-2023-04-27. Cloudflare's bot-detection WAF treats sudden concurrent bursts as bot scraping, triggering a403 Forbidden("Unable to load site") challenge and temporarily blocking subsequent requests from the client IP across all accounts.In addition,
account_stats.rswas still sendingUser-Agent: codex-cli/1.0.0without browser-like headers (which was previously updated inusage.rsvia #110).Changes
useAccounts.tsfrom 10 to 2 with a 150ms delay between consecutive requests.refreshMetadatarequests sequentially (concurrency 1 with 250ms delay) to avoid tripping the sensitiveaccounts/checkendpoint.refresh_all_usageandwarmup_all_accountsconcurrency in the Rust backend to 2.get_usage_with_chatgpt_authandfetch_chatgpt_account_metadatawithout rotating/burning the refresh token.build_chatgpt_headersincommands/account_stats.rsto sendBROWSER_USER_AGENTand standard browser headers (Accept-Language,Origin,Referer,sec-fetch-*).Rate limited by Cloudflare (403). Try again in a moment.) instead of genericAPI error: 403 Forbidden.