Skip to content

Add Gemini model fallback for overload resilience#3

Merged
Sarthak195 merged 1 commit into
mainfrom
gemini-model-fallback
Jul 15, 2026
Merged

Add Gemini model fallback for overload resilience#3
Sarthak195 merged 1 commit into
mainfrom
gemini-model-fallback

Conversation

@Sarthak195

Copy link
Copy Markdown
Owner

Why

Live judging exposed that gemini-3.5-flash intermittently returns 503 UNAVAILABLE ("high demand"). A single-model call surfaces that as a failed AI action.

What

generateJson() now tries the primary model (GEMINI_MODEL) and, on a transient/overload code (503/500/429), falls through a fallback chain (GEMINI_FALLBACK_MODELS, default gemini-3-flash-preview,gemini-flash-latest,gemini-2.0-flash). Non-retryable errors (bad key, invalid request) still fail fast. The client is injectable so the fallback logic is unit-tested without network.

Tests

+7 unit tests (69 total): isRetryable code classification, modelChain ordering/dedup, and the fallback loop (primary-overloaded→fallback, fail-fast on non-retryable, all-overloaded→throw, primary-success).

Verified: typecheck clean, next build succeeds, deployed to the live service.

Gemini returns 503 UNAVAILABLE when a model is overloaded (observed live on
gemini-3.5-flash). generateJson now tries the primary model (GEMINI_MODEL)
then falls through a fallback chain (GEMINI_FALLBACK_MODELS, default
gemini-3-flash-preview,gemini-flash-latest,gemini-2.0-flash) on transient
codes (503/500/429); non-retryable errors (bad key, invalid request) still
fail fast. Client is injectable for tests. +7 unit tests (69 total).
@Sarthak195
Sarthak195 merged commit 37b81c5 into main Jul 15, 2026
1 check passed
@Sarthak195
Sarthak195 deleted the gemini-model-fallback branch July 15, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant