Skip to content

feat(router): let a deployment set a timeout per service_tier - #47406

Merged
klu-berri merged 4 commits into
mainfrom
litellm_service_tier_timeouts_v2
Oct 19, 2026
Merged

klu-berri merged 4 commits into
mainfrom
litellm_service_tier_timeouts_v2

Conversation

@klu-berri

@klu-berri klu-berri commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • A deployment has one timeout, so flex requests time out on the standard budget

How it solves it:

  • New timeout_by_service_tier and stream_timeout_by_service_tier maps on litellm_params
  • A request whose service_tier matches a key uses that value, everything else is unchanged
  • A timeout the client sends (x-litellm-timeout, timeout) still wins

Same 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

model_list:
  - model_name: openai-gpt-5.1
    litellm_params:
      model: openai/gpt-5.1
      timeout: 610
      stream_timeout: 610
      timeout_by_service_tier:
        flex: 900
      stream_timeout_by_service_tier:
        flex: 900

Precedence per attempt: client timeout / x-litellm-timeout -> timeout_by_service_tier[service_tier] -> deployment timeout -> router and global defaults. Streams use the same order with stream_timeout and stream_timeout_by_service_tier. A streamed request whose tier is only in timeout_by_service_tier keeps the deployment's stream_timeout. The map values are validated as numbers when the deployment loads, so flex: fast fails at startup

User Flow

Before: a developer's flex request outlives the deployment timeout and fails, even though the admin would allow flex more time

  1. The admin sets timeout: 610 on openai-gpt-5.1, callers send "service_tier": "flex"
  2. The developer sends POST https://litellm-domain/v1/chat/completions with "service_tier": "flex" and no timeout header
  3. After 610 s they get HTTP 408 litellm.Timeout: APITimeoutError - Request timed out ... timeout value=610.0, same on POST /v1/responses
  4. Their only options are x-litellm-timeout: 900 on every flex call or a second model_list entry just for flex

After: the admin sets a flex timeout once and the same request completes

  1. The admin adds timeout_by_service_tier: {flex: 900} under the deployment's litellm_params and restarts
  2. The developer sends the same POST https://litellm-domain/v1/chat/completions with "service_tier": "flex" and no timeout header
  3. The proxy waits up to 900 s and returns HTTP 200, same on POST /v1/responses
  4. Requests without service_tier still get the 610 s budget, and a request carrying x-litellm-timeout: 2 still fails at 2 s

Relevant issues

Fixes #46205

Linear ticket

Resolves LIT-9703

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / 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 config

model_list:
  - model_name: openai-gpt-5.1
    litellm_params:
      model: openai/gpt-5.1
      api_base: http://127.0.0.1:9001/v1
      api_key: fake-key
      timeout: 3
      stream_timeout: 3
      max_retries: 0
      timeout_by_service_tier:
        flex: 12
      stream_timeout_by_service_tier:
        flex: 12
router_settings:
  num_retries: 0
post() {
  curl -sS --max-time 30 -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    "${@:3}" -d "$2" -w '\nHTTP %{http_code}, elapsed %{time_total}s\n' "http://127.0.0.1:4123/v1/$1"
}

Before (c0d88b4)

chat/completions, service_tier flex, no timeout header

  1. post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}'
  2. HTTP 408, elapsed 3.277825s, body litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=3.0, time taken=3.0 seconds

responses, service_tier flex, no timeout header

  1. post responses '{"model":"openai-gpt-5.1","service_tier":"flex","input":"hi"}'
  2. HTTP 408, elapsed 3.055761s, body litellm.Timeout: Timeout Error: OpenAIException - litellm.Timeout: Connection timed out. Timeout passed=3.0, time taken=3.001 seconds

chat/completions, no service_tier

  1. post chat/completions '{"model":"openai-gpt-5.1","messages":[{"role":"user","content":"hi"}]}'
  2. HTTP 200, elapsed 0.026862s, content served on default after 0s

chat/completions, service_tier flex, x-litellm-timeout: 2

  1. post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}' -H 'x-litellm-timeout: 2'
  2. HTTP 408, elapsed 2.064463s, body ... timeout value=2.0, time taken=2.01 seconds

After (7c803b8)

chat/completions, service_tier flex, no timeout header

  1. post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}'
  2. HTTP 200, elapsed 8.019720s, content served on flex after 8s, "service_tier":"flex"

responses, service_tier flex, no timeout header

  1. post responses '{"model":"openai-gpt-5.1","service_tier":"flex","input":"hi"}'
  2. HTTP 200, elapsed 8.018580s, status completed

chat/completions, no service_tier

  1. post chat/completions '{"model":"openai-gpt-5.1","messages":[{"role":"user","content":"hi"}]}'
  2. HTTP 200, elapsed 0.018048s, content served on default after 0s

chat/completions, service_tier flex, x-litellm-timeout: 2

  1. post chat/completions '{"model":"openai-gpt-5.1","service_tier":"flex","messages":[{"role":"user","content":"hi"}]}' -H 'x-litellm-timeout: 2'
  2. HTTP 408, elapsed 2.053959s, body ... timeout value=2.0, time taken=2.0 seconds

Type

🆕 New Feature

Caveats (if any)

Low

  • Tier names are not checked against the provider, an unknown key is simply never matched
  • A streamed flex request needs stream_timeout_by_service_tier too, timeout_by_service_tier alone leaves stream_timeout in charge
  • Not run against a real provider, the proof uses a scripted slow upstream
  • Docs for the two keys are a follow-up in litellm-docs

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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_tier timeout overrides on deployment litellm_params via timeout_by_service_tier and stream_timeout_by_service_tier, so requests with a matching service_tier (e.g. flex) can use a longer budget than the deployment’s default timeout / stream_timeout.

A shared get_service_tier_timeout lookup is wired into the Router timeout chain and LLM passthrough resolution, sitting after client timeout / stream_timeout and before generic deployment timeouts. Unmatched tiers and requests without service_tier behave as before; streaming still prefers stream_timeout_by_service_tier when 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.

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>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 32 untouched benchmarks


Comparing litellm_service_tier_timeouts_v2 (7c803b8) with main (b2f0f4d)

Open in CodSpeed

@kerry-berri

kerry-berri commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk high

Not approved at 7c803b8. risk is high, a human reviewer is needed.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Cursor Bugbot: Medium Risk at 7c803b8. 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. Bugbot run requested, finished in 2 min.
Bugbot Low is low, Medium and High are high. The judge model was not called.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@kerry-berri kerry-berri added the risk:high Sensitive, broad, or high-risk change label Oct 19, 2026
@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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.

@klu-berri
klu-berri merged commit 62ce515 into main Oct 19, 2026
90 checks passed
@klu-berri
klu-berri deleted the litellm_service_tier_timeouts_v2 branch October 19, 2026 21:27
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
Cartofante pushed a commit to CartoDB/litellm that referenced this pull request Oct 26, 2026
…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)
yuneng-berri pushed a commit that referenced this pull request Oct 28, 2026
* 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)
haowang1013 pushed a commit to directivegames/litellm that referenced this pull request Nov 3, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Sensitive, broad, or high-risk change

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)

4 participants