Skip to content

feat(router): support per-service-tier deployment timeouts - #47115

Closed
adc77 wants to merge 4 commits into
BerriAI:mainfrom
adc77:litellm_service_tier_timeouts
Closed

adc77 wants to merge 4 commits into
BerriAI:mainfrom
adc77:litellm_service_tier_timeouts

Conversation

@adc77

@adc77 adc77 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Flex requests share the deployment's ordinary timeout

How it solves it:

  • Add deployment timeout and stream-timeout maps by service tier
  • Preserve caller overrides and existing behavior for unmatched tiers
  • Accept typed deployments and preserve existing stream timeout settings
  • Preserve separate live-stream and fake-stream timeout budgets

Intentional product change: configured service tiers get their own timeout without changing the timeout for standard requests

User Flow

Before: a slow Flex request hits the ordinary deployment timeout

  1. The admin sets a one-second deployment timeout
  2. A developer sends service_tier: flex to /v1/chat/completions or /v1/responses, without a timeout header
  3. A two-second response times out with HTTP 408

After: the admin can allow Flex requests more time

  1. The admin keeps the one-second timeout and configures four seconds for Flex
  2. The developer sends the same request without a timeout header
  3. The response completes with HTTP 200; standard requests retain their original timeout

Relevant issues

Fixes #46205

Pre-Submission checklist

  • Meaningful regression tests added
  • Focused regression tests and registry/core timeout tests pass locally
  • Scope limited to deployment timeouts by service tier
  • Required PR CI checks and coverage pass
  • Automated reviews completed and findings addressed

Local make check and static router coverage pass. The router, registry, and core-timeout run passes 3,066 tests. Also verified 37 local HTTP cases at 7b02da03

The new split-timeout matrix fails eight cases if non-stream tier selection is bypassed and passes all 40 with the resolution. Both deployment dictionaries and typed deployments are covered

Screenshots / Proof of Fix

Not tested against real provider APIs. This proof uses a localhost LiteLLM proxy and a scripted HTTP upstream that responds after two seconds

Both runs use timeout: 1, stream_timeout: 1 and no retries. After adds:

timeout_by_service_tier:
  flex: 4
stream_timeout_by_service_tier:
  flex: 4

The same curl requests are used on both revisions. auth.headers supplies the local proxy bearer token

post() {
  curl -sS --max-time 12 -H @auth.headers \
    -H 'Content-Type: application/json' -d "$2" \
    -w '\nHTTP %{http_code}, elapsed %{time_total}s\n' \
    "http://127.0.0.1:19080/v1/$1"
}

Before (f370235)

Chat completions

  1. post chat/completions '{"model":"audit","service_tier":"flex","messages":[{"role":"user","content":"delay=2"}]}'
  2. HTTP 408, elapsed 1.436341s, request timed out at the one-second deployment limit

Responses

  1. post responses '{"model":"audit","service_tier":"flex","input":"delay=2"}'
  2. HTTP 408, elapsed 1.082554s, connection timed out with Timeout passed=1.0

After (7b02da0)

Chat completions

  1. post chat/completions '{"model":"audit","service_tier":"flex","messages":[{"role":"user","content":"delay=2"}]}'
  2. HTTP 200, elapsed 2.134317s, content audit ok, service_tier: flex

Responses

  1. post responses '{"model":"audit","service_tier":"flex","input":"delay=2"}'
  2. HTTP 200, elapsed 2.078123s, status completed, output text audit ok

Type

New Feature

Caveats

Low

  • Real-provider verification remains outstanding
  • Native Responses stream read-timeout fallback has an existing failure on main, unchanged by this patch

@CLAassistant

CLAassistant commented Oct 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed

codspeed Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing adc77:litellm_service_tier_timeouts (7b02da0) with main (f370235)

Open in CodSpeed

@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@BrickerP BrickerP left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES on head 7e01b1f045bf3a847877bbf07addcadb50d28782.

Blocker: _LITELLM_PARAMS_ADAPTER.validate_python(deployment["litellm_params"]) assumes a plain dict, but Router deployments commonly carry a LiteLLM_Params model. That raises ValidationError: Input should be a valid dictionary ... input_type=LiteLLM_Params inside _update_kwargs_with_deployment and breaks the existing helper-utils / tag / tools tests (CI unit job: 12 failed, including test_update_kwargs_with_deployment* — run 39040008906).

Also: when stream=True and only timeout_by_service_tier matches, deployment/router stream_timeout is skipped entirely — easy to shorten long stream budgets after adding a flex non-stream map.

Caller-override precedence and invalid-duration validation look solid once the adapter coercion is fixed.

Comment thread litellm/router.py Outdated
router_stream_timeout=_router_stream_timeout,
service_tier_timeout=get_service_tier_timeout(
_FALLBACK_HOP_ADAPTER.validate_python(kwargs),
_LITELLM_PARAMS_ADAPTER.validate_python(deployment["litellm_params"]),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the regression. _LITELLM_PARAMS_ADAPTER is TypeAdapter(Mapping[str, object]), so a live LiteLLM_Params instance fails with dict_type before timeout resolution runs.

CI evidence (unit/router): test_update_kwargs_with_deployment, test_update_kwargs_with_deployment_propagates_model_tags, …_merges_tags_without_duplicates, …_no_tags, …_merges_tools, and the malformed-tools-drop matrix all fail with that ValidationError on this head.

Coerce first, e.g. params if isinstance(params, Mapping) else params.model_dump(exclude_none=False) (same for self.default_litellm_params and the non-passthrough _get_timeout call below), or teach the adapter/helper to accept LiteLLM_Params.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a0af8a1 by normalizing typed deployments before timeout resolution. Added dictionary/model regressions, and the router CI job now passes

)
if stream_timeout is not None:
return stream_timeout
overrides: Final = deployment.get("timeout_by_service_tier")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream footgun: if stream is true and stream_timeout_by_service_tier is missing or has no entry for the tier, this falls through to timeout_by_service_tier and _get_timeout then early-returns that value — never consulting deployment/router stream_timeout (old _get_stream_timeout path).

Example: timeout=1, stream_timeout=30, timeout_by_service_tier={flex: 4}, request service_tier=flex&stream=true → 4 instead of 30.

Prefer: miss on the stream tier map → keep the existing stream timeout chain; only use the non-stream tier map for non-stream (or when no stream_timeout is configured). At minimum document + test that case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a0af8a1, preserving deployment/router stream limits unless a stream-tier entry matches. Regression coverage includes both routing paths. Could you take another look?

@github-actions

Copy link
Copy Markdown
Contributor

#46205 was fixed by #47406 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Oct 19, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Thanks for this. The feature landed in #47406 with the same keys and precedence, and you are credited as co-author there. Closing as superseded

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.

[Feature]: Let a deployment set a different timeout per service_tier (e.g. longer for flex)

3 participants