From 236975a74259a5d36bdc868c8eb16aaeb8449b69 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 31 May 2025 12:32:24 -0700 Subject: [PATCH] fix: allow users to disable aiohttp transport --- litellm/__init__.py | 3 ++- litellm/llms/custom_httpx/http_handler.py | 26 ++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/litellm/__init__.py b/litellm/__init__.py index ff3e93fcda..b99750b592 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -303,7 +303,8 @@ priority_reservation: Optional[Dict[str, float]] = None ######## Networking Settings ######## -use_aiohttp_transport: bool = True +use_aiohttp_transport: bool = True # Older variable, aiohttp is now the default. use disable_aiohttp_transport instead. +disable_aiohttp_transport: bool = False # Set this to true to use httpx instead force_ipv4: bool = False # when True, litellm will force ipv4 for all LLM requests. Some users have seen httpx ConnectionError when using ipv6. module_level_aclient = AsyncHTTPHandler( timeout=request_timeout, client_alias="module level aclient" diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index aaf3b92e6b..87941aedea 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -505,20 +505,30 @@ class AsyncHTTPHandler: @staticmethod def _should_use_aiohttp_transport() -> bool: """ - This is feature flagged for now and is opt in as we roll out to all users. + AiohttpTransport is the default transport for litellm. - Controlled by either - - litellm.use_aiohttp_transport or os.getenv("USE_AIOHTTP_TRANSPORT") = "True" + Httpx can be used by the following + - litellm.disable_aiohttp_transport = True + - os.getenv("DISABLE_AIOHTTP_TRANSPORT") = "True" """ + import os + from litellm.secret_managers.main import str_to_bool + ######################################################### + # Check if user disabled aiohttp transport + ######################################################## if ( - str_to_bool(os.getenv("USE_AIOHTTP_TRANSPORT", "False")) - or litellm.use_aiohttp_transport + litellm.disable_aiohttp_transport is True + or str_to_bool(os.getenv("DISABLE_AIOHTTP_TRANSPORT", "False")) is True ): - verbose_logger.debug("Using AiohttpTransport...") - return True - return False + return False + + ######################################################### + # Default: Use AiohttpTransport + ######################################################## + verbose_logger.debug("Using AiohttpTransport...") + return True @staticmethod def _create_aiohttp_transport(