Repository navigation
fix(router): honor stream_timeout on the SDK-native passthrough route (/v1/messages, /converse) - #41875
Conversation
Anthropic /v1/messages and Bedrock /converse resolve their upstream timeout through resolve_llm_passthrough_timeout, which only reads timeout / request_timeout and then falls back to the 600s pass_through default. A stream_timeout set on the deployment or in router_settings was never consulted on that route, while /chat/completions honors it through Router._get_stream_timeout. For a streaming call the resolver now checks stream_timeout at each level before the non-stream key (kwargs -> litellm_params -> router), mirroring _get_stream_timeout; non-streaming resolution is unchanged. The router passes its stream_timeout alongside the explicit timeout.
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
… route like the completion route
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
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 e75ad61. Configure here.
Merge origin/main into the branch. #41875 already honors stream_timeout on the bridged /v1/messages path and #43126 already ends the Anthropic stream with an error event, so this branch's router, timeout and bridge changes are dropped in favor of main. What remains is the Responses streaming iterator recording the text it already streamed on the failure log, so the spend row of a stream that died mid-way bills the partial completion tokens instead of zero
Replaces #41206 (fork head 74e9fb2, opened by @clonylu) on a
litellm_branch so CircleCI runs on it; the commits and their authors are carried over unchangedTLDR
Problem this solves:
stream_timeoutis ignored on/v1/messages(and Bedrock/converse)/chat/completions, which honors itHow it solves it:
stream_timeoutfirst for streaming callsRouter._get_stream_timeout: kwargs -> deployment -> routerRouter._get_timeout, so"stream": nullstill resolveslitellm_settings.request_timeoutranks on this route exactly where/chat/completionsranks it: aboverouter_settings.timeout, and belowstream_timeoutfor streams. The alternative, leaving this route onrouter_settings.timeoutalone, keeps/v1/messagesand/chat/completionson different timeouts whenever both settings are configured, which is the split this PR exists to closetimeout/request_timeout/pass_through_request_timeout/ 600s)User Flow
Before: a proxy admin sets
stream_timeout: 1800on a Claude deployment; long thinking turns over/v1/messagesstill die at 600sstream_timeout: 1800under the deployment'slitellm_params(orrouter_settings.stream_timeout: 1800) and restarts the proxyPOST https://litellm-domain/v1/messageswith"stream": true,max_tokens: 64000, adaptive thinking; the provider sendsmessage_startand then nothing for ~14 minutes while it thinksmessage_start, pings, then a clean close withstop_reason: "stop"and ~2 output tokens; HTTP status is 200https://litellm-domain/ui/?page=logsshows the request as a success with a 600s duration and near-zero outputAfter: the same deployment setting is respected on
/v1/messagesstream_timeout: 1800under the deployment'slitellm_params(orrouter_settings.stream_timeout: 1800) and restarts the proxyPOST https://litellm-domain/v1/messageswith"stream": truestop_reason: "max_tokens", 64000 output tokens)https://litellm-domain/ui/?page=logsshows the request as a success with the real output token countNon-streaming
/v1/messagescalls on the same deployment keep the previous behaviour (timeout/request_timeout/pass_through_request_timeout/ 600s)Relevant issues
Router._update_kwargs_with_deploymentroutes_ageneric_api_call_with_fallbacks(anthropic/v1/messages, bedrock/converse) throughresolve_llm_passthrough_timeout, which only readstimeout/request_timeoutand neverstream_timeout, so the documentedstream_timeoutknob (deployment orrouter_settings) has no effect on those routes./chat/completionsgoes throughRouter._get_timeoutand honors itAffected release
Linear ticket
Resolves LIT-7847
Pre-Submission checklist
uv run pytest tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py tests/test_litellm/test_router.py -k timeout -v(28 passed; the new streaming, winner-only validation, andrequest_timeoutprecedence cases fail onmainwithout the fix)make checkclean at the tip)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
QA run at e75ad61, the PR tip
Both legs boot the proxy from the repo checkout with
--num_workers 2, no DB, real Anthropic and OpenAI keys, the same config, the same client, and the same request bodies. Before is the merge base 15bd8b0, After is e75ad61Timeouts are scaled so a run takes seconds instead of minutes:
pass_through_request_timeout: 1is the generic timeout the bug falls back to androuter_settings.stream_timeout: 600is the setting the bug ignores. The provider's time to first byte on a large prompt (about 2s for claude-sonnet-5 on ~93k tokens, about 3.7s for gpt-5.6 at reasoning effort high on ~198k tokens) stands in for the minutes of mid-stream silence in the User Flow, since both are the same per-read idle timeout on the same socketBoot (each leg on its own random port):
python litellm/proxy/proxy_cli.py --config config.yaml --port $PORT --host 127.0.0.1 --num_workers 2Claude Code over /v1/messages (the User Flow's client)
export ANTHROPIC_AUTH_TOKEN=<proxy key>thenANTHROPIC_BASE_URL=http://127.0.0.1:$PORT ANTHROPIC_MODEL=claude-sonnet-5 claude01901 FINAL_LINE marker=lit7847-qa-sentinel, preceded by "Below is a ledger. Reply with only the marker value on its final line.", and press EnterBefore (15bd8b0): every streamed attempt dies at the 1s generic timeout although
stream_timeoutis 600; Claude Code retries 10 times over 4 minutes and gives up with the 408After (e75ad61): the same prompt against the same config answers
lit7847-qa-sentinelin 11scurl over every unified endpoint, plus the controls
One command per leg, run against each proxy in turn:
{"model": "claude-sonnet-5", "stream": true, "max_tokens": 64, "messages": [{"role": "user", "content": "Below is a ledger. ...<ledger, 308 KB>"}]}"stream": false(control)stream_timeout){"model": "gpt-5.6", "stream": true, "reasoning": {"effort": "high"}, "input": "Below is a ledger. ...<ledger x4, 1.2 MB>"}"stream": null(the endpoint treats it as non-streaming)"model": "claude-short"(deploymentstream_timeout: 1,timeout: 600)"stream": false(control)Before (15bd8b0):
After (e75ad61):
litellm_settings.request_timeout parity (the last commit)
Same rig and bodies, with the config changed so the only 1s timeout in play is
litellm_settings.request_timeout:router_settings.timeout: 600in place ofstream_timeout: 600,litellm_settings.request_timeout: 1, andgeneral_settings.pass_through_request_timeout: 600. The merge base lets streamed/v1/messagesthrough on the router timeout while streamed/chat/completionstimes out onrequest_timeout; the tip times both out the same wayBefore (15bd8b0):
After (e75ad61):
An intermediate tip (73fddb9) answered the
"stream": nullbody with a 500 (1 validation error for _TimeoutFields ... Input should be a valid boolean ... input_value=None); the tip reads the flag by truthiness and returns the generic 408 timeout above, matching the endpoint's non-streaming treatment of a null flagObservations from the run:
"stream": nullresolves as non-streaming: generic timeout, no 500Author's own report, not reproduced here: on a real deployment (v1.101.0-rc.1 with this change applied as a shim) a 15 MB Claude Code request over /v1/messages with
stream_timeout: 1800survived 839s of Vertex silence and completed with 64000 output tokens, where the unpatched proxy closed the identical request at 600s as an empty 200Type
🐛 Bug Fix
Caveats (if any)
Low
stream_timeoutis a per-read idle timeout applied per attempt, same as on/chat/completions; this PR does not add a total-request boundstream_timeouton a deployment whose provider can go silent for long stretches holds the connection longer; that is the documented trade-off of the settingstream_timeoutis shorter than its generic timeout now sees it enforced on/v1/messages,/v1/responses, and the router's SDK passthrough streams, where it was silently ignored before. Deployment-levelstream_timeoutwas already enforced by the messages handler, so those deployments see no change (the claude-short leg above behaves the same on both sides). Likewiselitellm_settings.request_timeoutnow bounds/v1/messagescalls the way it already bounded/chat/completions(the parity leg above): a deployment that relied on/v1/messagesoutliving a shortrequest_timeoutneedsstream_timeoutor a deployment-leveltimeoutset insteaddefault_litellm_params.stream_timeoutis now read for streaming passthrough calls, mirroringRouter._get_stream_timeout, whiledefault_litellm_params.timeoutis still not read for non-streaming ones; that non-streaming chain is unchanged from the merge base and stays out of scope herehttpx.Timeoutobject inkwargs["timeout"], say) raises a pydanticValidationErrorwhere the merge base raisedTypeErrorfromfloat(); both are unhandled, and a non-numeric value in a lower-precedence field is ignored, as it was beforeFinal 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
e75ad61 passes /live-pr-risk