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
[Chore]: feature flag aiohttp transport - users should opt into using aiohttp transport (#11132)
Ishaan Jaff9fc8d1c82e16
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex bbb937a538c..3ed894a21c5 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -300,7 +300,7 @@ custom_prometheus_metadata_labels: List[str] = []priority_reservation: Optional[Dict[str, float]] = None######## Networking Settings ########-use_aiohttp_transport: bool = True+use_aiohttp_transport: bool = Falseforce_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.pyindex fe80e47d127..ee6cafbaa7e 100644--- a/litellm/llms/custom_httpx/http_handler.py+++ b/litellm/llms/custom_httpx/http_handler.py@@ -494,7 +494,7 @@ class AsyncHTTPHandler:# httpx_aiohttp is included in litellm docker images and pip when python 3.9+ is used#########################################################if (- litellm.use_aiohttp_transport+ AsyncHTTPHandler._should_use_aiohttp_transport()and AsyncHTTPHandler.aiohttp_transport_exists()):return AsyncHTTPHandler._create_aiohttp_transport(@@ -506,6 +506,24 @@ class AsyncHTTPHandler:#########################################################return AsyncHTTPHandler._create_httpx_transport()+ @staticmethod+ def _should_use_aiohttp_transport() -> bool:+ """+ This is feature flagged for now and is opt in as we roll out to all users.++ Controlled by either+ - litellm.use_aiohttp_transport or os.getenv("USE_AIOHTTP_TRANSPORT") = "True"+ """+ from litellm.secret_managers.main import str_to_bool++ if (+ str_to_bool(os.getenv("USE_AIOHTTP_TRANSPORT", "False"))+ or litellm.use_aiohttp_transport+ ):+ verbose_logger.debug("Using AiohttpTransport...")+ return True+ return False+@staticmethoddef _create_aiohttp_transport(ssl_verify: Optional[bool] = None,diff --git a/litellm/proxy/health_endpoints/_health_endpoints.py b/litellm/proxy/health_endpoints/_health_endpoints.pyindex b6bf0a3515a..a283cf7866f 100644--- a/litellm/proxy/health_endpoints/_health_endpoints.py+++ b/litellm/proxy/health_endpoints/_health_endpoints.py@@ -11,6 +11,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request, Response, statusimport litellmfrom litellm._logging import verbose_proxy_loggerfrom litellm.constants import HEALTH_CHECK_TIMEOUT_SECONDS+from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandlerfrom litellm.proxy._types import (AlertType,CallInfo,@@ -547,6 +548,7 @@ async def health_readiness():"cache": cache_type,"litellm_version": version,"success_callbacks": success_callback_names,+ "use_aiohttp_transport": AsyncHTTPHandler._should_use_aiohttp_transport(),**db_health_status,}else:@@ -556,6 +558,7 @@ async def health_readiness():"cache": cache_type,"litellm_version": version,"success_callbacks": success_callback_names,+ "use_aiohttp_transport": AsyncHTTPHandler._should_use_aiohttp_transport(),}except Exception as e:raise HTTPException(status_code=503, detail=f"Service Unhealthy ({str(e)})")