The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: complete asyncio.iscoroutinefunction deprecation fix across codebase
Julio Quinteros Pro480974e0f9eb
diff --git a/litellm/integrations/custom_guardrail.py b/litellm/integrations/custom_guardrail.pyindex a8f1ba7ced0..56288ec5653 100644--- a/litellm/integrations/custom_guardrail.py+++ b/litellm/integrations/custom_guardrail.py@@ -824,6 +824,7 @@ def log_guardrail_information(func):"""import asyncioimport functools+ import inspectdef _infer_event_type_from_function_name(func_name: str,@@ -904,7 +905,7 @@ def log_guardrail_information(func):@functools.wraps(func)def wrapper(*args, **kwargs):- if asyncio.iscoroutinefunction(func):+ if inspect.iscoroutinefunction(func):return async_wrapper(*args, **kwargs)return sync_wrapper(*args, **kwargs)diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.pyindex 5d6d1fbc1c5..ad68f3851a8 100644--- a/litellm/litellm_core_utils/redact_messages.py+++ b/litellm/litellm_core_utils/redact_messages.py@@ -9,6 +9,7 @@import asyncioimport copy+import inspectfrom typing import TYPE_CHECKING, Any, Optionalimport litellm@@ -101,8 +102,8 @@ def perform_redaction(model_call_details: dict, result):# Redact resultif result is not None:# Check if result is a coroutine, async generator, or other async object - these cannot be deepcopied- if (asyncio.iscoroutine(result) or- asyncio.iscoroutinefunction(result) or+ if (asyncio.iscoroutine(result) or+ inspect.iscoroutinefunction(result) orhasattr(result, '__aiter__') or # async generatorhasattr(result, '__anext__')): # async iterator# For async objects, return a simple redacted response without deepcopydiff --git a/litellm/proxy/common_utils/performance_utils.py b/litellm/proxy/common_utils/performance_utils.pyindex f9537f85e2b..ec36f865cf1 100644--- a/litellm/proxy/common_utils/performance_utils.py+++ b/litellm/proxy/common_utils/performance_utils.py@@ -12,6 +12,7 @@ import asyncioimport atexitimport cProfileimport functools+import inspectimport threadingfrom pathlib import Path as PathLibfrom typing import Any, Callable, Optional@@ -100,7 +101,7 @@ def profile_endpoint(sampling_rate: float = 1.0):global _last_profile_file_path_last_profile_file_path = path- if asyncio.iscoroutinefunction(func):+ if inspect.iscoroutinefunction(func):@functools.wraps(func)async def async_wrapper(*args, **kwargs):is_sampling = _start_profiling_for_request(sampling_rate)diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.pyindex 6ce586b6cd8..acdb4efc21b 100644--- a/litellm/proxy/management_endpoints/key_management_endpoints.py+++ b/litellm/proxy/management_endpoints/key_management_endpoints.py@@ -11,6 +11,7 @@ All /key management endpointsimport asyncioimport copy+import inspectimport jsonimport osimport secrets@@ -1105,7 +1106,7 @@ async def generate_key_fn()if user_custom_key_generate is not None:- if asyncio.iscoroutinefunction(user_custom_key_generate):+ if inspect.iscoroutinefunction(user_custom_key_generate):result = await user_custom_key_generate(data) # type: ignoreelse:raise ValueError("user_custom_key_generate must be a coroutine")@@ -1257,7 +1258,7 @@ async def generate_service_account_key_fn(verbose_proxy_logger.debug("entered /key/generate")if user_custom_key_generate is not None:- if asyncio.iscoroutinefunction(user_custom_key_generate):+ if inspect.iscoroutinefunction(user_custom_key_generate):result = await user_custom_key_generate(data) # type: ignoreelse:raise ValueError("user_custom_key_generate must be a coroutine")diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.pyindex a57dafd1f00..d6d42019da5 100644--- a/litellm/proxy/management_endpoints/ui_sso.py+++ b/litellm/proxy/management_endpoints/ui_sso.py@@ -11,6 +11,7 @@ Has all /sso/* routesimport asyncioimport base64import hashlib+import inspectimport osimport secretsfrom copy import deepcopy@@ -2258,7 +2259,7 @@ class SSOAuthenticationHandler:user_defined_values: Optional[SSOUserDefinedValues] = Noneif user_custom_sso is not None:- if asyncio.iscoroutinefunction(user_custom_sso):+ if inspect.iscoroutinefunction(user_custom_sso):user_defined_values = await user_custom_sso(result) # type: ignoreelse:raise ValueError("user_custom_sso must be a coroutine function")diff --git a/tests/proxy_unit_tests/test_response_polling_handler.py b/tests/proxy_unit_tests/test_response_polling_handler.pyindex 26f8ac24adc..49624ddf505 100644--- a/tests/proxy_unit_tests/test_response_polling_handler.py+++ b/tests/proxy_unit_tests/test_response_polling_handler.py@@ -650,12 +650,12 @@ class TestBackgroundStreamingModule:def test_background_streaming_task_is_async(self):"""Test that background_streaming_task is an async function"""- import asyncio+ import inspectfrom litellm.proxy.response_polling.background_streaming import (background_streaming_task,)-- assert asyncio.iscoroutinefunction(background_streaming_task)++ assert inspect.iscoroutinefunction(background_streaming_task)class TestProviderResolutionForPolling: