feat(proxy): optional SSE keepalive comments during streaming silence#32763
Closed
henricook wants to merge 2 commits into
Closed
feat(proxy): optional SSE keepalive comments during streaming silence#32763henricook wants to merge 2 commits into
henricook wants to merge 2 commits into
Conversation
Reasoning models (gpt-5.x and o-series on /v1/responses) stream nothing
while thinking, so connections sit wire-silent for minutes. Idle-timeout
middleboxes between the client and LiteLLM (nginx: 60s default,
Envoy/Cilium: 300s, cloud load balancers) then kill the stream mid-turn.
Clients like Codex CLI surface this as 'stream disconnected before
completion' retry loops.
Opt-in via LITELLM_SSE_KEEPALIVE_INTERVAL_SECONDS (default 0 = off).
When enabled, SSE streaming responses emit a spec-ignorable comment
line (': keepalive') whenever the upstream generator is silent past
the interval. Wraps after first-chunk error sniffing, so error-to-JSON
status mapping is unaffected; disabled path is byte-identical.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
CI's ruff-format check covers whole files touched by the diff; this file had pre-existing unformatted hunks that now fall under it.
Author
|
Companion docs PR: BerriAI/litellm-docs#531 (the |
Contributor
Author
|
Discovered that I could force codex to request summaries with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Addresses #14953 (closed not-planned) — reopening the ask with a working implementation, tests, and e2e proof.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Real call through the proxy running at commit e9f4177: Azure
gpt-5.6-sol,reasoning.effort=high,LITELLM_SSE_KEEPALIVE_INTERVAL_SECONDS=3. The model reasons silently for ~30s and the keepalives land exactly in that gap:Without this, the same silence exceeds e.g. Envoy's 300s default
stream_idle_timeouton longer thinks and the connection is killed mid-turn. We run this in production (LiteLLM gateway fronting Azure GPT-5.6 for Codex CLI users behind a Cilium/Envoy ingress) — thestream disconnected before completionretry loops disappear.Tests:
pytest tests/test_litellm/proxy/test_common_request_processing.py— 169 passed (5 new inTestSSEKeepalive).Type
🆕 New Feature
Changes
/v1/responsesconnections sit wire-silent for minutes; any idle-timeout middlebox between client and proxy (nginx 60s default, Envoy/Cilium 300s, cloud LBs) kills them mid-turn. Users often can't raise those timeouts (shared infra) — same failure class as zai/glm-4.7 via Gateway: 30s idle timeout on api.z.ai drops tool_call streaming vercel/ai#12949 and Codex CLI requests consistently cut off at ~150s (stream disconnected); please increase or make timeout configurable openai/codex#3478.LITELLM_SSE_KEEPALIVE_INTERVAL_SECONDS(default 0 = disabled, zero behaviour change). When set, SSE streaming responses emit a comment line (: keepalive) whenever the upstream generator is silent past the interval.create_response()after first-chunk buffering, so first-chunk error sniffing / error-to-JSON status mapping is untouched; disabled path is byte-identical (covered by test).