Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
feat(gemini): per-model quota lockout instead of connection-wide
Chris Staley0038fe5ff1c3
diff --git a/src/sse/handlers/chat.ts b/src/sse/handlers/chat.tsindex ca57661076..efc81736ca 100644--- a/src/sse/handlers/chat.ts+++ b/src/sse/handlers/chat.ts@@ -567,7 +567,9 @@ async function handleSingleModelChat(}// 6. Mark account as quota-exhausted on 429 response- if (result.status === 429) {+ // For per-model quota providers (Gemini), a 429 on one model doesn't mean+ // the entire account is exhausted — skip connection-wide exhaustion marking.+ if (result.status === 429 && provider !== "gemini") {markAccountExhaustedFrom429(credentials.connectionId, provider);}diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.tsindex e465a7fd49..dd57be8069 100644--- a/src/sse/services/auth.ts+++ b/src/sse/services/auth.ts@@ -793,7 +793,8 @@ export async function markAccountUnavailable(| undefined;const isPassthroughProvider = provider && getPassthroughProviders().has(provider);- if ((isLocalProvider(connBaseUrl) || isPassthroughProvider) && status === 404 && provider && model) {+ const isPerModelQuotaProvider = isPassthroughProvider || provider === "gemini";+ if ((isLocalProvider(connBaseUrl) || isPerModelQuotaProvider) && status === 404 && provider && model) {const localCooldown = COOLDOWN_MS.notFoundLocal;lockModel(provider, connectionId, model, "not_found", localCooldown);log.info(@@ -803,12 +804,13 @@ export async function markAccountUnavailable(return { shouldFallback: true, cooldownMs: localCooldown };}- // ── 429 model-only lockout for passthrough providers ──- // For passthrough providers like Antigravity, each model has independent quota.- // A 429 on one model should NOT lock out the entire connection — other models- // may still have quota available. Use lockModel() instead of connection-wide- // rateLimitedUntil, same pattern as the 404 model-only lockout above.- if (isPassthroughProvider && status === 429 && provider && model) {+ // ── 429 model-only lockout for per-model quota providers ──+ // For providers where each model has independent quota (passthrough providers,+ // Gemini AI Studio), a 429 on one model should NOT lock out the entire connection+ // — other models may still have quota available. Use lockModel() instead of+ // connection-wide rateLimitedUntil.+ const hasPerModelQuota = isPassthroughProvider || provider === "gemini";+ if (hasPerModelQuota && status === 429 && provider && model) {const modelCooldown = cooldownMs || COOLDOWN_MS.rateLimit;lockModel(provider, connectionId, model, reason || "rate_limited", modelCooldown);log.info(