From 27193c9460336d282466c45e7968242650de1b06 Mon Sep 17 00:00:00 2001 From: amarrtech <272048731+amarrtech@users.noreply.github.com> Date: Sat, 26 Sep 2026 08:44:09 -0700 Subject: [PATCH 1/2] fix(http): honor request timeout for parameterized sync clients Signed-off-by: amarrtech <272048731+amarrtech@users.noreply.github.com> --- litellm/llms/custom_httpx/http_handler.py | 6 +++++- tests/unit/llms/custom_httpx/test_http_handler.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index 312f46bb021..4b45181ea79 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -1796,7 +1796,11 @@ def _get_httpx_client(params: dict | None = None) -> HTTPHandler: if params is not None: # Filter out params that are only used for cache key, not for HTTPHandler.__init__ - handler_params: Final = {k: v for k, v in params.items() if k != "disable_aiohttp_transport"} + configured_timeout: Final = params.get("timeout") + handler_params: Final = { + **{k: v for k, v in params.items() if k not in ("disable_aiohttp_transport", "timeout")}, + "timeout": configured_timeout if configured_timeout is not None else _default_cached_client_timeout(), + } _new_client = HTTPHandler(**handler_params) else: _new_client = HTTPHandler(timeout=_default_cached_client_timeout()) diff --git a/tests/unit/llms/custom_httpx/test_http_handler.py b/tests/unit/llms/custom_httpx/test_http_handler.py index 8358d15d30e..99a34637269 100644 --- a/tests/unit/llms/custom_httpx/test_http_handler.py +++ b/tests/unit/llms/custom_httpx/test_http_handler.py @@ -741,6 +741,18 @@ class TestDefaultCachedClientTimeoutHonorsRequestTimeout: client = get_async_httpx_client(llm_provider=LlmProviders.BEDROCK) assert client.timeout.read == 300.0 + def test_cached_sync_client_with_none_timeout_uses_explicit_request_timeout(self, monkeypatch: pytest.MonkeyPatch): + from litellm.caching.llm_caching_handler import LLMClientCache + + monkeypatch.setattr(litellm, "request_timeout", 300) + monkeypatch.setattr(litellm, "request_timeout_explicitly_set", True) + litellm.in_memory_llm_clients_cache = LLMClientCache() + + client = _get_httpx_client(params={"timeout": None}) + request = client.client.build_request("GET", "https://example.com") + + assert request.extensions["timeout"]["read"] == 300.0 + async def _read_http_request(reader: asyncio.StreamReader) -> None: raw = b"" From 44838201ced9916097824025992c3086de6fcfd8 Mon Sep 17 00:00:00 2001 From: amarrtech <272048731+amarrtech@users.noreply.github.com> Date: Sat, 26 Sep 2026 08:50:10 -0700 Subject: [PATCH 2/2] test(http): restore cached client state Signed-off-by: amarrtech <272048731+amarrtech@users.noreply.github.com> --- tests/unit/llms/custom_httpx/test_http_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/llms/custom_httpx/test_http_handler.py b/tests/unit/llms/custom_httpx/test_http_handler.py index 99a34637269..f914da7765d 100644 --- a/tests/unit/llms/custom_httpx/test_http_handler.py +++ b/tests/unit/llms/custom_httpx/test_http_handler.py @@ -746,7 +746,7 @@ class TestDefaultCachedClientTimeoutHonorsRequestTimeout: monkeypatch.setattr(litellm, "request_timeout", 300) monkeypatch.setattr(litellm, "request_timeout_explicitly_set", True) - litellm.in_memory_llm_clients_cache = LLMClientCache() + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache()) client = _get_httpx_client(params={"timeout": None}) request = client.client.build_request("GET", "https://example.com")