AIStudio2API
AIStudio2API copied to clipboard
[Bug] Consecutive 503 (code 14 "high demand") across pool exhausts MAX_ACCOUNT_SWITCHES in seconds and lacks brief backoff
发生了什么 / What happened
Summary
During temporary Google AI Studio traffic spikes, GenerateContent returns HTTP 503, protocol code 14: This model is currently experiencing high demand. Spikes in demand are usually temporary. Please try again later.
Because 503 is treated as a generic failure in settleAttempt:
- It immediately increments
retry.failures++againstMAX_ACCOUNT_SWITCHESwithout any backoff or short cooldown. - In a pool of 10+ accounts, a request cycles through 5 accounts in ~15 seconds, burns
MAX_ACCOUNT_SWITCHES=5, and immediately returns503to the client—even though subsequent accounts in the pool were healthy. - Subsequent requests immediately hit the same accounts and fail again.
Observed Log Evidence (sanitized)
In our logs over 5 hours, gemini-4-hydrogen recorded 117 account switches due to 503 code 14, evenly distributed across all 7 enabled accounts (17–21 times each).
Example timeline (13:17:54 to 13:18:17):
13:17:59account_1->503 code 1413:18:02account_2->503 code 1413:18:06account_3->503 code 1413:18:10account_4->503 code 1413:18:14account_5->503 code 1413:18:17account_6->503 code 14(failures = 6 > MAX_ACCOUNT_SWITCHES=5-> request aborts with 503). The very next request at13:18:48cycled through the exact same accounts and failed again.
Root Cause Pointer
In internal/app/runtime.go (settleAttempt):
503setsquotaFailure = false.- Unlike
429(which applies a cooldown and doesn't count againstretry.failures),503incrementsretry.failures++. - No temporary model-level pause or jittered backoff exists for
503 code 14.
Suggested Improvement
- For
HTTP 503with protocol code14(high demand), don't burnMAX_ACCOUNT_SWITCHESimmediately on every switch (or treat503spike switches similarly to quota switches bounded bylen(EnabledAccounts())). - Apply a brief transient cool-off (e.g. 15–30 seconds) on that specific model for that account, or add a short delay (200–500ms) before trying the next account so transient cluster spikes settle without failing the user request.
版本 / Version
v0.3.13