From 2d66fa182463876260d2a502a081f8c668ca1c6f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 27 Feb 2026 05:19:04 +0000 Subject: [PATCH] fix: wire keepalive_timeout through to gunicorn server path The KEEPALIVE_TIMEOUT env var / --keepalive_timeout CLI flag was only wired to uvicorn's timeout_keep_alive parameter. The gunicorn code path was missing this, causing a mismatch between ALB idle timeout and proxy keep-alive when running with --run_gunicorn. Fix: Add keepalive_timeout parameter to _run_gunicorn_server and set gunicorn's 'keepalive' option accordingly. Co-authored-by: Ishaan Jaff --- litellm/proxy/proxy_cli.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index 2bc1c8f8e98..ad0dae59691 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -188,6 +188,7 @@ class ProxyInitializationHelpers: ssl_certfile_path: str, ssl_keyfile_path: str, max_requests_before_restart: Optional[int] = None, + keepalive_timeout: Optional[int] = None, ): """ Run litellm with `gunicorn` @@ -272,6 +273,10 @@ class ProxyInitializationHelpers: if max_requests_before_restart is not None: gunicorn_options["max_requests"] = max_requests_before_restart + # Wire keepalive timeout through to gunicorn (matches uvicorn's timeout_keep_alive) + if keepalive_timeout is not None: + gunicorn_options["keepalive"] = keepalive_timeout + if ssl_certfile_path is not None and ssl_keyfile_path is not None: print( # noqa f"\033[1;32mLiteLLM Proxy: Using SSL with certfile: {ssl_certfile_path} and keyfile: {ssl_keyfile_path}\033[0m\n" # noqa @@ -860,6 +865,7 @@ def run_server( # noqa: PLR0915 ssl_certfile_path=ssl_certfile_path, ssl_keyfile_path=ssl_keyfile_path, max_requests_before_restart=max_requests_before_restart, + keepalive_timeout=keepalive_timeout, ) elif run_hypercorn is True: ProxyInitializationHelpers._init_hypercorn_server(