Repository navigation
feat(router): let a deployment set a timeout per service_tier - #47406
Conversation
Adds timeout_by_service_tier and stream_timeout_by_service_tier to a deployment's litellm_params. A request whose service_tier matches a key uses that value in place of the deployment's timeout or stream_timeout. A timeout the client sends still wins and requests without a matching tier are unchanged Co-authored-by: adc77 <amandogra2016@gmail.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@litellm-stampbot |
litellm-stampbot: risk highNot approved at Rules (
Cursor Bugbot: Medium Risk at Pushes do not re-run this check. Comment |
|
bugbot run |
|
@litellm-stampbot |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 7c803b8. Configure here.
…I#47406) Backport of BerriAI#47406 to stable/1.103.x Cherry-picked from 62ce515 (main)
…I#47406) * feat(router): let a deployment set a timeout per service_tier Adds timeout_by_service_tier and stream_timeout_by_service_tier to a deployment's litellm_params. A request whose service_tier matches a key uses that value in place of the deployment's timeout or stream_timeout. A timeout the client sends still wins and requests without a matching tier are unchanged Co-authored-by: adc77 <amandogra2016@gmail.com> * style(router): sort the request_timeout_resolver import * fix(router): read the service tier maps without the untyped params get * fix(router): look the service tier timeout up through a typed get --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: adc77 <amandogra2016@gmail.com> Backport of BerriAI#47406 to stable/1.106.x Cherry-picked from 62ce515 (main)
* feat(router): let a deployment set a timeout per service_tier Adds timeout_by_service_tier and stream_timeout_by_service_tier to a deployment's litellm_params. A request whose service_tier matches a key uses that value in place of the deployment's timeout or stream_timeout. A timeout the client sends still wins and requests without a matching tier are unchanged Co-authored-by: adc77 <amandogra2016@gmail.com> * style(router): sort the request_timeout_resolver import * fix(router): read the service tier maps without the untyped params get * fix(router): look the service tier timeout up through a typed get --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: adc77 <amandogra2016@gmail.com> (cherry picked from commit 62ce515)
…I#47406) * feat(router): let a deployment set a timeout per service_tier Adds timeout_by_service_tier and stream_timeout_by_service_tier to a deployment's litellm_params. A request whose service_tier matches a key uses that value in place of the deployment's timeout or stream_timeout. A timeout the client sends still wins and requests without a matching tier are unchanged Co-authored-by: adc77 <amandogra2016@gmail.com> * style(router): sort the request_timeout_resolver import * fix(router): read the service tier maps without the untyped params get * fix(router): look the service tier timeout up through a typed get --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: adc77 <amandogra2016@gmail.com> Backport of BerriAI#47406 to stable/1.105.x. Cherry-picked from 62ce515 (main).
TLDR
Problem this solves:
timeout, so flex requests time out on the standard budgetHow it solves it:
timeout_by_service_tierandstream_timeout_by_service_tiermaps onlitellm_paramsservice_tiermatches a key uses that value, everything else is unchangedx-litellm-timeout,timeout) still winsSame two config keys and the same precedence as #47115, re-done with one lookup in the Router's existing timeout chain instead of new helper modules. The contributor is credited as co-author on the commit
Precedence per attempt: client
timeout/x-litellm-timeout->timeout_by_service_tier[service_tier]-> deploymenttimeout-> router and global defaults. Streams use the same order withstream_timeoutandstream_timeout_by_service_tier. A streamed request whose tier is only intimeout_by_service_tierkeeps the deployment'sstream_timeout. The map values are validated as numbers when the deployment loads, soflex: fastfails at startupUser Flow
Before: a developer's flex request outlives the deployment timeout and fails, even though the admin would allow flex more time
timeout: 610onopenai-gpt-5.1, callers send"service_tier": "flex""service_tier": "flex"and no timeout headerlitellm.Timeout: APITimeoutError - Request timed out ... timeout value=610.0, same on POST /v1/responsesx-litellm-timeout: 900on every flex call or a second model_list entry just for flexAfter: the admin sets a flex timeout once and the same request completes
timeout_by_service_tier: {flex: 900}under the deployment'slitellm_paramsand restarts"service_tier": "flex"and no timeout headerservice_tierstill get the 610 s budget, and a request carryingx-litellm-timeout: 2still fails at 2 sRelevant issues
Fixes #46205
Linear ticket
Resolves LIT-9703
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Local proxy on port 4123 pointed at a scripted OpenAI-compatible upstream on 127.0.0.1:9001 that answers immediately for the default tier and after 8 s for
service_tier: flex. No real provider is involved because the behavior under test is the proxy giving up before a slow upstream answers, which a real provider cannot be made to do on demand. Both runs use the same configBefore (c0d88b4)
chat/completions, service_tier flex, no timeout header
post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}'HTTP 408, elapsed 3.277825s, bodylitellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=3.0, time taken=3.0 secondsresponses, service_tier flex, no timeout header
post responses '{"model":"openai-gpt-5.1","service_tier":"flex","input":"hi"}'HTTP 408, elapsed 3.055761s, bodylitellm.Timeout: Timeout Error: OpenAIException - litellm.Timeout: Connection timed out. Timeout passed=3.0, time taken=3.001 secondschat/completions, no service_tier
post chat/completions '{"model":"openai-gpt-5.1","messages":[{"role":"user","content":"hi"}]}'HTTP 200, elapsed 0.026862s, contentserved on default after 0schat/completions, service_tier flex, x-litellm-timeout: 2
post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}' -H 'x-litellm-timeout: 2'HTTP 408, elapsed 2.064463s, body... timeout value=2.0, time taken=2.01 secondsAfter (7c803b8)
chat/completions, service_tier flex, no timeout header
post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}'HTTP 200, elapsed 8.019720s, contentserved on flex after 8s,"service_tier":"flex"responses, service_tier flex, no timeout header
post responses '{"model":"openai-gpt-5.1","service_tier":"flex","input":"hi"}'HTTP 200, elapsed 8.018580s, statuscompletedchat/completions, no service_tier
post chat/completions '{"model":"openai-gpt-5.1","messages":[{"role":"user","content":"hi"}]}'HTTP 200, elapsed 0.018048s, contentserved on default after 0schat/completions, service_tier flex, x-litellm-timeout: 2
post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}' -H 'x-litellm-timeout: 2'HTTP 408, elapsed 2.053959s, body... timeout value=2.0, time taken=2.0 secondsType
🆕 New Feature
Caveats (if any)
Low
stream_timeout_by_service_tiertoo,timeout_by_service_tieralone leavesstream_timeoutin chargeFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/91eace52e53e4656a3be452c07a810d6
Open in Devin Desktop: https://app.devin.ai/desktop/session/91eace52e53e4656a3be452c07a810d6?variant=devin
Requested by: @kerrylu-berri
Note
Medium Risk
Changes request timeout resolution on the router and passthrough paths; wrong precedence or tier matching could cause unexpected 408s or overly long upstream waits, though client overrides still win.
Overview
Adds per-
service_tiertimeout overrides on deploymentlitellm_paramsviatimeout_by_service_tierandstream_timeout_by_service_tier, so requests with a matchingservice_tier(e.g.flex) can use a longer budget than the deployment’s defaulttimeout/stream_timeout.A shared
get_service_tier_timeoutlookup is wired into the Router timeout chain and LLM passthrough resolution, sitting after clienttimeout/stream_timeoutand before generic deployment timeouts. Unmatched tiers and requests withoutservice_tierbehave as before; streaming still prefersstream_timeout_by_service_tierwhen present.Types and OpenAPI/UI schema are extended for the new maps; unit tests cover precedence for router and passthrough paths.
Reviewed by Cursor Bugbot for commit 7c803b8. Bugbot is set up for automated code reviews on this repo. Configure here.