Skip to content

feat(router): add opt-in flag to honor Retry-After with multiple deployments - #34408

Draft
unfitcoder101 wants to merge 3 commits into
BerriAI:mainfrom
unfitcoder101:fix/router-honor-retry-after
Draft

unfitcoder101 wants to merge 3 commits into
BerriAI:mainfrom
unfitcoder101:fix/router-honor-retry-after

Conversation

@unfitcoder101

Copy link
Copy Markdown

Fixes #34399

Problem

_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. Sibling deployments frequently share the same throttled upstream (e.g. two deployments with different api_keys pointing at the same backend), so instant retries hammer the throttled endpoint and burn through num_retries well 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 asserts timeout == 0 in this scenario. Rather than changing default behavior, this adds an opt-in respect_retry_after_with_multiple_deployments flag (default False) to Router.__init__. Default behavior is completely unchanged and verified unchanged by a new test.

Fix

When respect_retry_after_with_multiple_deployments=True, an explicit Retry-After header is honored even with healthy sibling deployments present.

Tests

  • Default behavior unchanged (instant retry, even with Retry-After present)
  • Opt-in honors Retry-After with multiple deployments
  • Opt-in still allows instant retry when no Retry-After header is present

All existing router retry tests pass except one pre-existing, unrelated environmental failure (missing ANTHROPIC_API_KEY locally), confirmed identical with and without this change via git stash.

…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

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing unfitcoder101:fix/router-honor-retry-after (e8e3f4d) with litellm_internal_staging (e7df795)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (f6a1050) during the generation of this report, so 32a5562 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@unfitcoder101

Copy link
Copy Markdown
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).

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:33
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
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

No deployments
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.

[Bug]: Router ignores Retry-After (instant retry) for multi-deployment model groups sharing one rate-limited upstream

2 participants