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
[Bug Fix] Azure Blob Storage fixes (#10059)
Ishaan Jaffa9e8a36f89c3
diff --git a/litellm/constants.py b/litellm/constants.pyindex 0f35520b2ed..f25c7c71e41 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -21,6 +21,9 @@ DEFAULT_MAX_TOKENS = 256 # used when providers need a defaultMAX_SIZE_PER_ITEM_IN_MEMORY_CACHE_IN_KB = 1024 # 1MB = 1024KBSINGLE_DEPLOYMENT_TRAFFIC_FAILURE_THRESHOLD = 1000 # Minimum number of requests to consider "reasonable traffic". Used for single-deployment cooldown logic.+########## Networking constants ##############################################################+_DEFAULT_TTL_FOR_HTTPX_CLIENTS = 3600 # 1 hour, re-use the same httpx client for 1 hour+########### v2 Architecture constants for managing writing updates to the database ###########REDIS_UPDATE_BUFFER_KEY = "litellm_spend_update_buffer"REDIS_DAILY_SPEND_UPDATE_BUFFER_KEY = "litellm_daily_spend_update_buffer"diff --git a/litellm/integrations/azure_storage/azure_storage.py b/litellm/integrations/azure_storage/azure_storage.pyindex 24a3f5749ad..6ffb1e542fc 100644--- a/litellm/integrations/azure_storage/azure_storage.py+++ b/litellm/integrations/azure_storage/azure_storage.py@@ -1,12 +1,13 @@import asyncioimport jsonimport os+import timeimport uuidfrom datetime import datetime, timedeltafrom typing import List, Optionalfrom litellm._logging import verbose_logger-from litellm.constants import AZURE_STORAGE_MSFT_VERSION+from litellm.constants import _DEFAULT_TTL_FOR_HTTPX_CLIENTS, AZURE_STORAGE_MSFT_VERSIONfrom litellm.integrations.custom_batch_logger import CustomBatchLoggerfrom litellm.llms.azure.common_utils import get_azure_ad_token_from_entra_idfrom litellm.llms.custom_httpx.http_handler import (@@ -48,14 +49,17 @@ class AzureBlobStorageLogger(CustomBatchLogger):"Missing required environment variable: AZURE_STORAGE_FILE_SYSTEM")self.azure_storage_file_system: str = _azure_storage_file_system+ self._service_client = None+ # Time that the azure service client expires, in order to reset the connection pool and keep it fresh+ self._service_client_timeout: Optional[float] = None# Internal variables used for Token based authentication- self.azure_auth_token: Optional[- str- ] = None # the Azure AD token to use for Azure Storage API requests- self.token_expiry: Optional[- datetime- ] = None # the expiry time of the currentAzure AD token+ self.azure_auth_token: Optional[str] = (+ None # the Azure AD token to use for Azure Storage API requests+ )+ self.token_expiry: Optional[datetime] = (+ None # the expiry time of the currentAzure AD token+ )asyncio.create_task(self.periodic_flush())self.flush_lock = asyncio.Lock()@@ -324,6 +328,25 @@ class AzureBlobStorageLogger(CustomBatchLogger):f"AzureBlobStorageLogger is only available for premium users. {CommonProxyErrors.not_premium_user}")+ async def get_service_client(self):+ from azure.storage.filedatalake.aio import DataLakeServiceClient++ # expire old clients to recover from connection issues+ if (+ self._service_client_timeout+ and self._service_client+ and self._service_client_timeout > time.time()+ ):+ await self._service_client.close()+ self._service_client = None+ if not self._service_client:+ self._service_client = DataLakeServiceClient(+ account_url=f"https://{self.azure_storage_account_name}.dfs.core.windows.net",+ credential=self.azure_storage_account_key,+ )+ self._service_client_timeout = time.time() + _DEFAULT_TTL_FOR_HTTPX_CLIENTS+ return self._service_client+async def upload_to_azure_data_lake_with_azure_account_key(self, payload: StandardLoggingPayload):@@ -332,13 +355,10 @@ class AzureBlobStorageLogger(CustomBatchLogger):This is used when Azure Storage Account Key is set - Azure Storage Account Key does not work directly with Azure Rest API"""- from azure.storage.filedatalake.aio import DataLakeServiceClient# Create an async service client- service_client = DataLakeServiceClient(- account_url=f"https://{self.azure_storage_account_name}.dfs.core.windows.net",- credential=self.azure_storage_account_key,- )++ service_client = await self.get_service_client()# Get file system clientfile_system_client = service_client.get_file_system_client(file_system=self.azure_storage_file_systemdiff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.pyindex f1aa5627dcc..627dd8c9f93 100644--- a/litellm/llms/custom_httpx/http_handler.py+++ b/litellm/llms/custom_httpx/http_handler.py@@ -8,6 +8,7 @@ import httpxfrom httpx import USE_CLIENT_DEFAULT, AsyncHTTPTransport, HTTPTransportimport litellm+from litellm.constants import _DEFAULT_TTL_FOR_HTTPX_CLIENTSfrom litellm.litellm_core_utils.logging_utils import track_llm_api_timingfrom litellm.types.llms.custom_http import *@@ -31,7 +32,6 @@ headers = {# https://www.python-httpx.org/advanced/timeouts_DEFAULT_TIMEOUT = httpx.Timeout(timeout=5.0, connect=5.0)-_DEFAULT_TTL_FOR_HTTPX_CLIENTS = 3600 # 1 hour, re-use the same httpx client for 1 hourdef mask_sensitive_info(error_message):diff --git a/requirements.txt b/requirements.txtindex dca68b6f93b..ebc525bafa9 100644--- a/requirements.txt+++ b/requirements.txt@@ -29,7 +29,7 @@ python-multipart==0.0.18 # admin UIPillow==11.0.0azure-ai-contentsafety==1.0.0 # for azure content safetyazure-identity==1.16.1 # for azure content safety-azure-storage-file-datalake==12.15.0 # for azure buck storage logging+azure-storage-file-datalake==12.20.0 # for azure buck storage loggingopentelemetry-api==1.25.0opentelemetry-sdk==1.25.0opentelemetry-exporter-otlp==1.25.0@@ -51,4 +51,4 @@ tenacity==8.2.3 # for retrying requests, when litellm.num_retries setpydantic==2.10.2 # proxy + openai req.jsonschema==4.22.0 # validating json schemawebsockets==13.1.0 # for realtime API-####\ No newline at end of file+####