From 580362e7aa02ca4a69aae5b7fb1e82e70bec1974 Mon Sep 17 00:00:00 2001 From: RoomWithOutRoof Date: Fri, 3 Apr 2026 06:05:39 +0800 Subject: [PATCH] fix(timeout): parse llm provider from model name instead of hardcoding "openai" - Use get_llm_provider() to dynamically determine the LLM provider - Fall back to "openai" if parsing fails - Remove TODO comments that requested this fix - Improve error handling with kwargs.get() instead of direct access --- litellm/timeout.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/litellm/timeout.py b/litellm/timeout.py index f9bf036cea2..43f66882e2b 100644 --- a/litellm/timeout.py +++ b/litellm/timeout.py @@ -18,6 +18,7 @@ from inspect import iscoroutinefunction from threading import Thread from litellm.exceptions import Timeout +from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider def timeout(timeout_duration: float = 0.0, exception_to_raise=Timeout): @@ -53,11 +54,17 @@ def timeout(timeout_duration: float = 0.0, exception_to_raise=Timeout): result = future.result(timeout=local_timeout_duration) except futures.TimeoutError: thread.stop_loop() - model = args[0] if len(args) > 0 else kwargs["model"] + model = args[0] if len(args) > 0 else kwargs.get("model") + llm_provider = "openai" + if model: + try: + _, llm_provider, _, _ = get_llm_provider(model) + except Exception: + pass # keep default "openai" on error raise exception_to_raise( f"A timeout error occurred. The function call took longer than {local_timeout_duration} second(s).", - model=model, # [TODO]: replace with logic for parsing out llm provider from model name - llm_provider="openai", + model=model, + llm_provider=llm_provider, ) thread.stop_loop() return result @@ -75,11 +82,17 @@ def timeout(timeout_duration: float = 0.0, exception_to_raise=Timeout): ) return value except asyncio.TimeoutError: - model = args[0] if len(args) > 0 else kwargs["model"] + model = args[0] if len(args) > 0 else kwargs.get("model") + llm_provider = "openai" + if model: + try: + _, llm_provider, _, _ = get_llm_provider(model) + except Exception: + pass # keep default "openai" on error raise exception_to_raise( f"A timeout error occurred. The function call took longer than {local_timeout_duration} second(s).", - model=model, # [TODO]: replace with logic for parsing out llm provider from model name - llm_provider="openai", + model=model, + llm_provider=llm_provider, ) if iscoroutinefunction(func):