feat: add SSE keep-alive comments for idle streaming responses (#51034)

Signed-off-by: fuzzifikation <40043768+fuzzifikation@users.noreply.github.com>
This commit is contained in:
Dieter Schwarzmann
2026-08-23 18:13:02 -07:00
committed by GitHub
parent a7195188a4
commit 585bb07c70
6 changed files with 381 additions and 2 deletions
+14
View File
@@ -137,6 +137,13 @@ class BaseFrontendArgs:
"""If set to True, enable tracking server_load_metrics in the app state."""
enable_force_include_usage: bool = False
"""If set to True, including usage on every request."""
sse_keep_alive_interval: int = 0
"""Send an SSE keep-alive comment line every this many seconds when a
`/v1/chat/completions` or `/v1/completions` streaming response is idle
(queued, prefill, or between tokens), to prevent reverse proxies/tunnels
with read timeouts from closing the connection. Defaults to 0, which
disables keep-alive comments entirely.
"""
enable_tokenizer_info_endpoint: bool = False
"""Enable the `/tokenizer_info` endpoint. May expose chat
templates and other tokenizer configuration."""
@@ -426,6 +433,13 @@ def validate_parsed_serve_args(args: argparse.Namespace):
if args.enable_log_outputs and not args.enable_log_requests:
raise TypeError("Error: --enable-log-outputs requires --enable-log-requests")
# SSE keep-alive interval must be zero (disabled) or a positive integer.
if getattr(args, "sse_keep_alive_interval", 0) < 0:
raise ValueError(
"Error: --sse-keep-alive-interval must be a non-negative integer "
"(0 disables keep-alive comments)."
)
if getattr(args, "enable_per_request_metrics", False) and getattr(
args, "disable_log_stats", False
):