Skip to content

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]

Revert "Enable System Proxy Support for aiohttp Transport (#11616)"

Ishaan Jaff098fb0307a7d
diff --git a/litellm/__init__.py b/litellm/__init__.py
index caffd2427ee..5ebffaf10a4 100644
--- a/litellm/__init__.py
+++ b/litellm/__init__.py
@@ -135,22 +135,22 @@ prometheus_initialize_budget_metrics: Optional[bool] = False
require_auth_for_metrics_endpoint: Optional[bool] = False
argilla_batch_size: Optional[int] = None
datadog_use_v1: Optional[bool] = False # if you want to use v1 datadog logged payload.
-gcs_pub_sub_use_v1: Optional[
- bool
-] = False # if you want to use v1 gcs pubsub logged payload
-generic_api_use_v1: Optional[
- bool
-] = False # if you want to use v1 generic api logged payload
+gcs_pub_sub_use_v1: Optional[bool] = (
+ False # if you want to use v1 gcs pubsub logged payload
+)
+generic_api_use_v1: Optional[bool] = (
+ False # if you want to use v1 generic api logged payload
+)
argilla_transformation_object: Optional[Dict[str, Any]] = None
-_async_input_callback: List[
- Union[str, Callable, CustomLogger]
-] = [] # internal variable - async custom callbacks are routed here.
-_async_success_callback: List[
- Union[str, Callable, CustomLogger]
-] = [] # internal variable - async custom callbacks are routed here.
-_async_failure_callback: List[
- Union[str, Callable, CustomLogger]
-] = [] # internal variable - async custom callbacks are routed here.
+_async_input_callback: List[Union[str, Callable, CustomLogger]] = (
+ []
+) # internal variable - async custom callbacks are routed here.
+_async_success_callback: List[Union[str, Callable, CustomLogger]] = (
+ []
+) # internal variable - async custom callbacks are routed here.
+_async_failure_callback: List[Union[str, Callable, CustomLogger]] = (
+ []
+) # internal variable - async custom callbacks are routed here.
pre_call_rules: List[Callable] = []
post_call_rules: List[Callable] = []
turn_off_message_logging: Optional[bool] = False
@@ -158,18 +158,18 @@ log_raw_request_response: bool = False
redact_messages_in_exceptions: Optional[bool] = False
redact_user_api_key_info: Optional[bool] = False
filter_invalid_headers: Optional[bool] = False
-add_user_information_to_llm_headers: Optional[
- bool
-] = None # adds user_id, team_id, token hash (params from StandardLoggingMetadata) to request headers
+add_user_information_to_llm_headers: Optional[bool] = (
+ None # adds user_id, team_id, token hash (params from StandardLoggingMetadata) to request headers
+)
store_audit_logs = False # Enterprise feature, allow users to see audit logs
### end of callbacks #############
-email: Optional[
- str
-] = None # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
-token: Optional[
- str
-] = None # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
+email: Optional[str] = (
+ None # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
+)
+token: Optional[str] = (
+ None # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
+)
telemetry = True
max_tokens: int = DEFAULT_MAX_TOKENS # OpenAI Defaults
drop_params = bool(os.getenv("LITELLM_DROP_PARAMS", False))
@@ -253,20 +253,24 @@ enable_loadbalancing_on_batch_endpoints: Optional[bool] = None
enable_caching_on_provider_specific_optional_params: bool = (
False # feature-flag for caching on optional params - e.g. 'top_k'
)
-caching: bool = False # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
-caching_with_models: bool = False # # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
-cache: Optional[
- Cache
-] = None # cache object <- use this - https://docs.litellm.ai/docs/caching
+caching: bool = (
+ False # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
+)
+caching_with_models: bool = (
+ False # # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648
+)
+cache: Optional[Cache] = (
+ None # cache object <- use this - https://docs.litellm.ai/docs/caching
+)
default_in_memory_ttl: Optional[float] = None
default_redis_ttl: Optional[float] = None
default_redis_batch_cache_expiry: Optional[float] = None
model_alias_map: Dict[str, str] = {}
model_group_alias_map: Dict[str, str] = {}
max_budget: float = 0.0 # set the max budget across all providers
-budget_duration: Optional[
- str
-] = None # proxy only - resets budget after fixed duration. You can set duration as seconds ("30s"), minutes ("30m"), hours ("30h"), days ("30d").
+budget_duration: Optional[str] = (
+ None # proxy only - resets budget after fixed duration. You can set duration as seconds ("30s"), minutes ("30m"), hours ("30h"), days ("30d").
+)
default_soft_budget: float = (
DEFAULT_SOFT_BUDGET # by default all litellm proxy keys have a soft budget of 50.0
)
@@ -275,11 +279,15 @@ forward_traceparent_to_llm_provider: bool = False
_current_cost = 0.0 # private variable, used if max budget is set
error_logs: Dict = {}
-add_function_to_prompt: bool = False # if function calling not supported by api, append function call details to system prompt
+add_function_to_prompt: bool = (
+ False # if function calling not supported by api, append function call details to system prompt
+)
client_session: Optional[httpx.Client] = None
aclient_session: Optional[httpx.AsyncClient] = None
model_fallbacks: Optional[List] = None # Deprecated for 'litellm.fallbacks'
-model_cost_map_url: str = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
+model_cost_map_url: str = (
+ "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
+)
suppress_debug_info = False
dynamodb_table_name: Optional[str] = None
s3_callback_params: Optional[Dict] = None
@@ -309,12 +317,13 @@ priority_reservation: Optional[Dict[str, float]] = None
######## Networking Settings ########
-use_aiohttp_transport: bool = True # Older variable, aiohttp is now the default. use disable_aiohttp_transport instead.
+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
-disable_aiohttp_trust_env: bool = (
- False # when True, aiohttp will not trust environment variables for proxy settings
+force_ipv4: bool = (
+ False # when True, litellm will force ipv4 for all LLM requests. Some users have seen httpx ConnectionError when using ipv6.
)
-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"
)
@@ -328,13 +337,13 @@ fallbacks: Optional[List] = None
context_window_fallbacks: Optional[List] = None
content_policy_fallbacks: Optional[List] = None
allowed_fails: int = 3
-num_retries_per_request: Optional[
- int
-] = None # for the request overall (incl. fallbacks + model retries)
+num_retries_per_request: Optional[int] = (
+ None # for the request overall (incl. fallbacks + model retries)
+)
####### SECRET MANAGERS #####################
-secret_manager_client: Optional[
- Any
-] = None # list of instantiated key management clients - e.g. azure kv, infisical, etc.
+secret_manager_client: Optional[Any] = (
+ None # list of instantiated key management clients - e.g. azure kv, infisical, etc.
+)
_google_kms_resource_name: Optional[str] = None
_key_management_system: Optional[KeyManagementSystem] = None
_key_management_settings: KeyManagementSettings = KeyManagementSettings()
@@ -1152,12 +1161,12 @@ from .types.llms.custom_llm import CustomLLMItem
from .types.utils import GenericStreamingChunk
custom_provider_map: List[CustomLLMItem] = []
-_custom_providers: List[
- str
-] = [] # internal helper util, used to track names of custom providers
-disable_hf_tokenizer_download: Optional[
- bool
-] = None # disable huggingface tokenizer download. Defaults to openai clk100
+_custom_providers: List[str] = (
+ []
+) # internal helper util, used to track names of custom providers
+disable_hf_tokenizer_download: Optional[bool] = (
+ None # disable huggingface tokenizer download. Defaults to openai clk100
+)
global_disable_no_log_param: bool = False
### PASSTHROUGH ###
diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py
index 0ced937396e..87eea27c4ad 100644
--- a/litellm/llms/custom_httpx/http_handler.py
+++ b/litellm/llms/custom_httpx/http_handler.py
@@ -545,8 +545,6 @@ class AsyncHTTPHandler:
- [Default] If force_ipv4 is False, it will create an AiohttpTransport with default settings
"""
from litellm.llms.custom_httpx.aiohttp_transport import LiteLLMAiohttpTransport
-
- from litellm.secret_managers.main import str_to_bool
#########################################################
# If ssl_verify is None, set it to True
@@ -555,20 +553,10 @@ class AsyncHTTPHandler:
#########################################################
if ssl_verify is None:
ssl_verify = True
-
- #########################################################
- # Check if user disabled aiohttp trust env
- # When True, aiohttp will not trust environment variables for proxy settings
- ########################################################
- disable_trust_env = (
- litellm.disable_aiohttp_trust_env is True
- or str_to_bool(os.getenv("DISABLE_AIOHTTP_TRUST_ENV", "False")) is True
- )
verbose_logger.debug("Creating AiohttpTransport...")
return LiteLLMAiohttpTransport(
client=lambda: ClientSession(
- trust_env=not disable_trust_env,
connector=TCPConnector(
verify_ssl=ssl_verify,
ssl_context=ssl_context,
diff --git a/tests/test_litellm/llms/custom_httpx/test_http_handler.py b/tests/test_litellm/llms/custom_httpx/test_http_handler.py
index ebd759b79ba..75fb0b92984 100644
--- a/tests/test_litellm/llms/custom_httpx/test_http_handler.py
+++ b/tests/test_litellm/llms/custom_httpx/test_http_handler.py
@@ -120,70 +120,3 @@ async def test_ssl_verification_with_aiohttp_transport():
# assert both litellm transport and aiohttp session have ssl_verify=False
assert transport_connector._ssl == aiohttp_session.connector._ssl
-
-
-async def test_disable_aiohttp_trust_env_with_env_variable(monkeypatch):
- """Test aiohttp transport respects DISABLE_AIOHTTP_TRUST_ENV environment variable"""
- # Set environment variable to disable trust env
- monkeypatch.setenv("DISABLE_AIOHTTP_TRUST_ENV", "True")
-
- # Ensure aiohttp transport is enabled
- litellm.disable_aiohttp_transport = False
-
- # Create async client
- client = AsyncHTTPHandler()
-
- # Get the transport (should be LiteLLMAiohttpTransport)
- transport = client.client._transport
- assert isinstance(transport, LiteLLMAiohttpTransport)
-
- # Get the aiohttp ClientSession
- client_session = transport._get_valid_client_session()
-
- # Verify that trust_env is False when DISABLE_AIOHTTP_TRUST_ENV is True
- assert client_session._trust_env is False
-
-
-async def test_disable_aiohttp_trust_env_with_litellm_setting():
- """Test aiohttp transport respects litellm.disable_aiohttp_trust_env setting"""
- # Set litellm setting to disable trust env
- litellm.disable_aiohttp_trust_env = True
-
- # Ensure aiohttp transport is enabled
- litellm.disable_aiohttp_transport = False
-
- # Create async client
- client = AsyncHTTPHandler()
-
- # Get the transport (should be LiteLLMAiohttpTransport)
- transport = client.client._transport
- assert isinstance(transport, LiteLLMAiohttpTransport)
-
- # Get the aiohttp ClientSession
- client_session = transport._get_valid_client_session()
-
- # Verify that trust_env is False when litellm.disable_aiohttp_trust_env is True
- assert client_session._trust_env is False
-
-
-async def test_enable_aiohttp_trust_env_default():
- """Test aiohttp transport enables trust_env by default"""
- # Ensure both settings are disabled/default
- litellm.disable_aiohttp_trust_env = False
- litellm.disable_aiohttp_transport = False
-
- # Create async client
- client = AsyncHTTPHandler()
-
- # Get the transport (should be LiteLLMAiohttpTransport)
- transport = client.client._transport
- assert isinstance(transport, LiteLLMAiohttpTransport)
-
- # Get the aiohttp ClientSession
- client_session = transport._get_valid_client_session()
-
- # Verify that trust_env is True by default
- assert client_session._trust_env is True