diff --git a/enterprise/enterprise_hooks/aporia_ai.py b/enterprise/enterprise_hooks/aporia_ai.py index 14a9a06f6..7f5339f30 100644 --- a/enterprise/enterprise_hooks/aporia_ai.py +++ b/enterprise/enterprise_hooks/aporia_ai.py @@ -26,7 +26,10 @@ from typing import List from datetime import datetime import aiohttp, asyncio from litellm._logging import verbose_proxy_logger -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + get_async_httpx_client, + httpxSpecialProvider, +) import httpx import json from litellm.types.guardrails import GuardrailEventHooks @@ -40,8 +43,8 @@ class AporiaGuardrail(CustomGuardrail): def __init__( self, api_key: Optional[str] = None, api_base: Optional[str] = None, **kwargs ): - self.async_handler = AsyncHTTPHandler( - timeout=httpx.Timeout(timeout=600.0, connect=5.0) + self.async_handler = get_async_httpx_client( + llm_provider=httpxSpecialProvider.GuardrailCallback ) self.aporia_api_key = api_key or os.environ["APORIO_API_KEY"] self.aporia_api_base = api_base or os.environ["APORIO_API_BASE"] diff --git a/litellm/integrations/galileo.py b/litellm/integrations/galileo.py index 51d845fcb..70b5c3b01 100644 --- a/litellm/integrations/galileo.py +++ b/litellm/integrations/galileo.py @@ -8,7 +8,10 @@ from pydantic import BaseModel, Field import litellm from litellm._logging import verbose_logger from litellm.integrations.custom_logger import CustomLogger -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + get_async_httpx_client, + httpxSpecialProvider, +) # from here: https://docs.rungalileo.io/galileo/gen-ai-studio-products/galileo-observe/how-to/logging-data-via-restful-apis#structuring-your-records @@ -39,8 +42,8 @@ class GalileoObserve(CustomLogger): self.base_url = os.getenv("GALILEO_BASE_URL", None) self.project_id = os.getenv("GALILEO_PROJECT_ID", None) self.headers = None - self.async_httpx_handler = AsyncHTTPHandler( - timeout=httpx.Timeout(timeout=600.0, connect=5.0) + self.async_httpx_handler = get_async_httpx_client( + llm_provider=httpxSpecialProvider.LoggingCallback ) pass diff --git a/litellm/integrations/gcs_bucket_base.py b/litellm/integrations/gcs_bucket_base.py index 073f0f265..0f71fe829 100644 --- a/litellm/integrations/gcs_bucket_base.py +++ b/litellm/integrations/gcs_bucket_base.py @@ -13,15 +13,18 @@ from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.logging_utils import ( convert_litellm_response_object_to_dict, ) -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + get_async_httpx_client, + httpxSpecialProvider, +) class GCSBucketBase(CustomLogger): def __init__(self, bucket_name: Optional[str] = None) -> None: from litellm.proxy.proxy_server import premium_user - self.async_httpx_client = AsyncHTTPHandler( - timeout=httpx.Timeout(timeout=600.0, connect=5.0) + self.async_httpx_client = get_async_httpx_client( + llm_provider=httpxSpecialProvider.LoggingCallback ) self.path_service_account_json = os.getenv("GCS_PATH_SERVICE_ACCOUNT", None) self.BUCKET_NAME = bucket_name or os.getenv("GCS_BUCKET_NAME", None) diff --git a/litellm/integrations/lago.py b/litellm/integrations/lago.py index b3db53301..e0238e311 100644 --- a/litellm/integrations/lago.py +++ b/litellm/integrations/lago.py @@ -13,7 +13,11 @@ import httpx import litellm from litellm import verbose_logger from litellm.integrations.custom_logger import CustomLogger -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + HTTPHandler, + get_async_httpx_client, + httpxSpecialProvider, +) def get_utc_datetime(): @@ -30,7 +34,9 @@ class LagoLogger(CustomLogger): def __init__(self) -> None: super().__init__() self.validate_environment() - self.async_http_handler = AsyncHTTPHandler() + self.async_http_handler = get_async_httpx_client( + llm_provider=httpxSpecialProvider.LoggingCallback + ) self.sync_http_handler = HTTPHandler() def validate_environment(self): diff --git a/litellm/integrations/langsmith.py b/litellm/integrations/langsmith.py index d245a6e2c..3ee55b3e9 100644 --- a/litellm/integrations/langsmith.py +++ b/litellm/integrations/langsmith.py @@ -16,7 +16,11 @@ from pydantic import BaseModel # type: ignore import litellm from litellm._logging import verbose_logger from litellm.integrations.custom_logger import CustomLogger -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + AsyncHTTPHandler, + get_async_httpx_client, + httpxSpecialProvider, +) class LangsmithInputs(BaseModel): @@ -61,8 +65,8 @@ class LangsmithLogger(CustomLogger): self.langsmith_base_url = os.getenv( "LANGSMITH_BASE_URL", "https://api.smith.langchain.com" ) - self.async_httpx_client = AsyncHTTPHandler( - timeout=httpx.Timeout(timeout=600.0, connect=5.0) + self.async_httpx_client = get_async_httpx_client( + llm_provider=httpxSpecialProvider.LoggingCallback ) def _prepare_log_data(self, kwargs, response_obj, start_time, end_time): diff --git a/litellm/integrations/openmeter.py b/litellm/integrations/openmeter.py index 6905fd789..19460e001 100644 --- a/litellm/integrations/openmeter.py +++ b/litellm/integrations/openmeter.py @@ -12,7 +12,12 @@ import httpx import litellm from litellm import verbose_logger from litellm.integrations.custom_logger import CustomLogger -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + AsyncHTTPHandler, + HTTPHandler, + get_async_httpx_client, + httpxSpecialProvider, +) def get_utc_datetime(): @@ -29,7 +34,9 @@ class OpenMeterLogger(CustomLogger): def __init__(self) -> None: super().__init__() self.validate_environment() - self.async_http_handler = AsyncHTTPHandler() + self.async_http_handler = get_async_httpx_client( + llm_provider=httpxSpecialProvider.LoggingCallback + ) self.sync_http_handler = HTTPHandler() def validate_environment(self): diff --git a/litellm/integrations/prometheus_helpers/prometheus_api.py b/litellm/integrations/prometheus_helpers/prometheus_api.py index 13ccc1562..472c3b61b 100644 --- a/litellm/integrations/prometheus_helpers/prometheus_api.py +++ b/litellm/integrations/prometheus_helpers/prometheus_api.py @@ -8,11 +8,16 @@ import time import litellm from litellm._logging import verbose_logger -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + get_async_httpx_client, + httpxSpecialProvider, +) PROMETHEUS_URL = litellm.get_secret("PROMETHEUS_URL") PROMETHEUS_SELECTED_INSTANCE = litellm.get_secret("PROMETHEUS_SELECTED_INSTANCE") -async_http_handler = AsyncHTTPHandler() +async_http_handler = get_async_httpx_client( + llm_provider=httpxSpecialProvider.LoggingCallback +) async def get_metric_from_prometheus( diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index eab3f9c38..42e289b87 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -25,7 +25,11 @@ from litellm._logging import verbose_logger, verbose_proxy_logger from litellm.caching import DualCache from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.llms.custom_httpx.http_handler import ( + AsyncHTTPHandler, + get_async_httpx_client, + httpxSpecialProvider, +) from litellm.proxy._types import ( AlertType, CallInfo, @@ -187,7 +191,9 @@ class SlackAlerting(CustomLogger): self.alerting = alerting self.alert_types = alert_types self.internal_usage_cache = internal_usage_cache or DualCache() - self.async_http_handler = AsyncHTTPHandler() + self.async_http_handler = get_async_httpx_client( + llm_provider=httpxSpecialProvider.LoggingCallback + ) self.alert_to_webhook_url = alert_to_webhook_url self.is_running = False self.alerting_args = SlackAlertingArgs(**alerting_args)