From 9ae30edbdda734056d864f8b7ef811f60a6102de Mon Sep 17 00:00:00 2001 From: harish876 Date: Tue, 14 Apr 2026 23:25:43 +0000 Subject: [PATCH] modify default timeout values, replacing hard coded ones with default values defined --- litellm/constants.py | 3 +++ litellm/llms/custom_httpx/http_handler.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index a25ecc17cd1..0893e7a77be 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -420,7 +420,10 @@ DEFAULT_MAX_TOKENS_FOR_TRITON = int(os.getenv("DEFAULT_MAX_TOKENS_FOR_TRITON", 2 # per-request/model timeout—see ``CompletionTimeout.resolve`` in completion_timeout.py. MCP uses # dedicated timeouts (e.g. `MCP_CLIENT_TIMEOUT`), not `request_timeout`. DEFAULT_REQUEST_TIMEOUT_SECONDS: float = 6000.0 +# Pair used for default httpx clients when no custom timeout is passed: read/write +# deadline and connect handshake (see ``http_handler`` cached handler paths). COMPLETION_HTTP_FALLBACK_SECONDS: float = 600.0 +HTTP_HANDLER_CONNECT_TIMEOUT_SECONDS: float = 5.0 request_timeout: float = float( os.getenv("REQUEST_TIMEOUT", str(int(DEFAULT_REQUEST_TIMEOUT_SECONDS))) ) diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index 001547557d4..86fa762e0b7 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -30,7 +30,9 @@ from litellm.constants import ( AIOHTTP_KEEPALIVE_TIMEOUT, AIOHTTP_NEEDS_CLEANUP_CLOSED, AIOHTTP_TTL_DNS_CACHE, + COMPLETION_HTTP_FALLBACK_SECONDS, DEFAULT_SSL_CIPHERS, + HTTP_HANDLER_CONNECT_TIMEOUT_SECONDS, ) from litellm.litellm_core_utils.logging_utils import track_llm_api_timing from litellm.types.llms.custom_http import * @@ -70,7 +72,10 @@ def get_default_headers() -> dict: headers = get_default_headers() # https://www.python-httpx.org/advanced/timeouts -_DEFAULT_TIMEOUT = httpx.Timeout(timeout=5.0, connect=5.0) +_DEFAULT_TIMEOUT = httpx.Timeout( + timeout=COMPLETION_HTTP_FALLBACK_SECONDS, + connect=HTTP_HANDLER_CONNECT_TIMEOUT_SECONDS, +) def _prepare_request_data_and_content( @@ -1244,7 +1249,7 @@ def get_async_httpx_client( _new_client = AsyncHTTPHandler(**handler_params) else: _new_client = AsyncHTTPHandler( - timeout=httpx.Timeout(timeout=600.0, connect=5.0), + timeout=_DEFAULT_TIMEOUT, shared_session=shared_session, ) @@ -1293,7 +1298,7 @@ def _get_httpx_client(params: Optional[dict] = None) -> HTTPHandler: } _new_client = HTTPHandler(**handler_params) else: - _new_client = HTTPHandler(timeout=httpx.Timeout(timeout=600.0, connect=5.0)) + _new_client = HTTPHandler(timeout=_DEFAULT_TIMEOUT) cache.set_cache( key=_cache_key_name,