Repository navigation
feat(router): add opt-in flag to honor Retry-After with multiple deployments - #34408
Draft
unfitcoder101 wants to merge 3 commits into
Draft
unfitcoder101 wants to merge 3 commits into
unfitcoder101 wants to merge 3 commits into
Conversation
…oyments _time_to_sleep_before_retry unconditionally returns 0 (instant retry) whenever a model group has more than one healthy deployment, discarding any Retry-After header the upstream provider sent. This is deliberate existing behavior (assumes failover to a different, healthy deployment) and is locked in by an existing test (test_timeout_for_rate_limit_error_with_healthy_deployments), so this adds an opt-in flag rather than changing the default. Sibling deployments frequently share the same throttled upstream or rate limit (e.g. two deployments pointing at the same backend with different api_keys), in which case instant retries just hammer the throttled endpoint and burn through num_retries well within the provider's advertised backoff window. Added respect_retry_after_with_multiple_deployments (default False) to Router.__init__. When enabled, an explicit Retry-After header is honored even with healthy sibling deployments present. Default behavior is completely unchanged. Added regression tests: opt-in honors Retry-After with multiple deployments, opt-in still allows instant retry when no Retry-After is present, and default behavior is verified unchanged. Fixes BerriAI#34399
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Author
|
Heads up — the osv-scan failure (gitpython/postcss CVEs) is pre-existing on litellm_internal_staging itself, unrelated to this PR's diff (confirmed via git diff on uv.lock/package-lock.json — no changes from this branch). |
Closed
1 task done
devin-ai-integration
Bot
changed the base branch from
litellm_internal_staging
to
main
September 23, 2026 15:33
This branch has not been deployed
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.
Fixes #34399
Problem
_time_to_sleep_before_retryunconditionally returns 0 (instant retry) whenever a model group has more than one healthy deployment, discarding anyRetry-Afterheader the upstream provider sent. Sibling deployments frequently share the same throttled upstream (e.g. two deployments with differentapi_keys pointing at the same backend), so instant retries hammer the throttled endpoint and burn throughnum_retrieswell within the provider's advertised backoff window.Why opt-in, not a default change
The existing instant-retry-on-healthy-deployments behavior is deliberate and locked in by an existing test (
test_timeout_for_rate_limit_error_with_healthy_deployments), which explicitly assertstimeout == 0in this scenario. Rather than changing default behavior, this adds an opt-inrespect_retry_after_with_multiple_deploymentsflag (defaultFalse) toRouter.__init__. Default behavior is completely unchanged and verified unchanged by a new test.Fix
When
respect_retry_after_with_multiple_deployments=True, an explicitRetry-Afterheader is honored even with healthy sibling deployments present.Tests
Retry-Afterpresent)Retry-Afterwith multiple deploymentsRetry-Afterheader is presentAll existing router retry tests pass except one pre-existing, unrelated environmental failure (missing
ANTHROPIC_API_KEYlocally), confirmed identical with and without this change viagit stash.