From c73639b5c752c35927f2249b919cd64acce3765a Mon Sep 17 00:00:00 2001 From: Charlie Freeman <243496084+cf3901646@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:18:43 +0800 Subject: [PATCH] fix(utils): allow httpx.Timeout for mistral, openai-compatible and httpx-based providers (#47822) --- litellm/utils.py | 52 +++++++++++++++++-- .../test_completion_timeout_resolution.py | 23 +++++++- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index 7de7ce6188d..236f64ffdf2 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -2846,15 +2846,61 @@ def token_counter( ) +HTTPX_TIMEOUT_SUPPORTED_PROVIDERS: Final[frozenset[str]] = frozenset( + { + "openai", + "azure", + "bedrock", + "bedrock_mantle", + "custom_openai", + "text-completion-openai", + "openai_like", + "chatgpt", + "anthropic", + "anthropic_text", + "mistral", + "codestral", + "cohere", + "cohere_chat", + "ollama", + "ollama_chat", + "openrouter", + "vertex_ai", + "gemini", + "deepseek", + "groq", + "together_ai", + "fireworks_ai", + "perplexity", + "xai", + "zai", + "cerebras", + "sambanova", + "baseten", + "cloudflare", + "databricks", + "hosted_vllm", + "minimax", + "huggingface", + } +) + + def supports_httpx_timeout(custom_llm_provider: str) -> bool: """ Helper function to know if a provider implementation supports httpx timeout """ - supported_providers: Final = ["openai", "azure", "bedrock"] - - if custom_llm_provider in supported_providers: + if custom_llm_provider in HTTPX_TIMEOUT_SUPPORTED_PROVIDERS: return True + try: + from litellm.constants import openai_compatible_providers + + if custom_llm_provider in openai_compatible_providers: + return True + except ImportError: + pass + return False diff --git a/tests/unit/test_completion_timeout_resolution.py b/tests/unit/test_completion_timeout_resolution.py index 37b5cceef5a..00614fc447c 100644 --- a/tests/unit/test_completion_timeout_resolution.py +++ b/tests/unit/test_completion_timeout_resolution.py @@ -134,7 +134,7 @@ def test_httpx_timeout_coerced_for_provider_without_httpx_timeout_support(): out = CompletionTimeout.resolve( t, {}, - "azure_ai", + "replicate", global_timeout=None, supports_httpx_timeout=supports_httpx_timeout, stream_kind=StreamKind.NOT_STREAMED, @@ -182,7 +182,7 @@ def test_sdk_timeout_coerces_read_timeout_for_providers_without_httpx_support( CompletionTimeout.resolve( SDKTimeout(connect=2.0, read=read_timeout, write=5.0, pool=7.0), {}, - "azure_ai", + "replicate", global_timeout=None, supports_httpx_timeout=supports_httpx_timeout, stream_kind=StreamKind.NOT_STREAMED, @@ -231,3 +231,22 @@ def test_fake_stream_with_only_a_stream_timeout_keeps_the_global_request_timeout ) == 600.0 ) + + +@pytest.mark.parametrize( + "provider", + ("mistral", "custom_openai", "anthropic", "cohere", "ollama", "groq", "deepseek"), +) +def test_httpx_timeout_preserved_for_extended_providers(provider: str) -> None: + t = httpx.Timeout(10.0, connect=1.0) + out = CompletionTimeout.resolve( + t, + {}, + provider, + global_timeout=None, + supports_httpx_timeout=supports_httpx_timeout, + stream_kind=StreamKind.NOT_STREAMED, + ) + assert out is t + assert isinstance(out, httpx.Timeout) + assert out.connect == 1.0