AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Feature] Model fallback routing when all eligible accounts are quota-cooled for the requested model

Open photobrand opened this issue 1 week ago • 0 comments

想要什么,用来做什么 / What you want and what for

What I want & Use Case

In multi-account environments, high-tier models like gemini-4-hydrogen or gemini-4-neon occasionally exhaust daily tokens across all accounts (generate_content_tokens_per_model_per_user, limit: 10000000) with reset times of 20+ hours.

Currently, once all accounts are in cooldown for that specific model, requests immediately fail with 429 rate_limit_exceeded / AllCoolingError. This interrupts automated coding agents (e.g. OpenCode, DSH, Cursor, Claude Code), forcing the user to manually stop their work, open settings, and reconfigure model mappings.

Because other models (e.g. gemini-4-neon, gemini-3.8-flash, gemini-3.5-flash-lite) often still have full quota on those exact same accounts, having an optional model fallback configuration would ensure seamless, uninterrupted operation.

Proposed Solution

  1. Configuration (MODEL_FALLBACKS): Allow defining fallback chains in .env / Settings, e.g.: MODEL_FALLBACKS=gemini-4-hydrogen:gemini-4-neon,gemini-3.8-flash;gemini-4-neon:gemini-4-hydrogen,gemini-3.8-flash
  2. Behavior in generateWithRetry (internal/app/runtime.go): When acquireWarmLease confirms all candidate accounts for selection.ModelID are cooled down (AllCoolingError where earliest reset > 1 minute):
    • If a fallback model is configured and has available accounts, log an INFO event (模型额度耗尽,自动回退到 <fallback_model>) and switch the request target to the fallback model.
    • If no fallback model is configured or all fallback models are also exhausted, return 429 AllCoolingError as usual.

版本 / Version

v0.3.13

photobrand avatar Nov 21 '26 19:11 photobrand