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
Merge branch 'main' into litellm_metrics_pod_lock_manager
Ishaan Jaffdf51d8bcfac0
diff --cc litellm/proxy/db/db_transaction_queue/base_update_queue.pyindex 2bf23931279,924c4e6905c..873164c047c--- a/litellm/proxy/db/db_transaction_queue/base_update_queue.py+++ b/litellm/proxy/db/db_transaction_queue/base_update_queue.py@@@ -2,14 -2,9 +2,15 @@@Base class for in memory buffer for database transactions"""import asyncio+from typing import Optionalfrom litellm._logging import verbose_proxy_logger+from litellm._service_logger import ServiceLogging++service_logger_obj = (+ ServiceLogging()+) # used for tracking metrics for In memory buffer, redis buffer, pod lock manager+ from litellm.constants import MAX_IN_MEMORY_QUEUE_FLUSH_COUNT, MAX_SIZE_IN_MEMORY_QUEUEclass BaseUpdateQueue:@@@ -30,12 -23,11 +32,18 @@@"""Get all updates from the queue."""updates = []while not self.update_queue.empty():+ # Circuit breaker to ensure we're not stuck dequeuing updates. Protect CPU utilization+ if len(updates) >= MAX_IN_MEMORY_QUEUE_FLUSH_COUNT:+ verbose_proxy_logger.warning(+ "Max in memory queue flush count reached, stopping flush"+ )+ breakupdates.append(await self.update_queue.get())return updates++ async def _emit_new_item_added_to_queue_event(+ self,+ queue_size: Optional[int] = None,+ ):+ """placeholder, emit event when a new item is added to the queue"""+ passdiff --cc litellm/proxy/db/db_transaction_queue/daily_spend_update_queue.pyindex afae431370d,2900824e19b..c61d24d50ed--- a/litellm/proxy/db/db_transaction_queue/daily_spend_update_queue.py+++ b/litellm/proxy/db/db_transaction_queue/daily_spend_update_queue.py@@@ -1,5 -1,6 +1,6 @@@import asyncio+ from copy import deepcopy-from typing import Dict, List+from typing import Dict, List, Optionalfrom litellm._logging import verbose_proxy_loggerfrom litellm.proxy._types import DailyUserSpendTransaction@@@ -95,21 -115,5 +119,21 @@@ class DailySpendUpdateQueue(BaseUpdateQ]daily_transaction["failed_requests"] += payload["failed_requests"]else:- aggregated_daily_spend_update_transactions[_key] = payload+ aggregated_daily_spend_update_transactions[_key] = deepcopy(payload)return aggregated_daily_spend_update_transactions++ async def _emit_new_item_added_to_queue_event(+ self,+ queue_size: Optional[int] = None,+ ):+ asyncio.create_task(+ service_logger_obj.async_service_success_hook(+ service=ServiceTypes.IN_MEMORY_DAILY_SPEND_UPDATE_QUEUE,+ duration=0,+ call_type="_emit_new_item_added_to_queue_event",+ event_metadata={+ "gauge_labels": ServiceTypes.IN_MEMORY_DAILY_SPEND_UPDATE_QUEUE,+ "gauge_value": queue_size,+ },+ )+ )diff --cc litellm/proxy/db/db_transaction_queue/spend_update_queue.pyindex 60e9379751a,ee2ce59eda0..98a9e5088ad--- a/litellm/proxy/db/db_transaction_queue/spend_update_queue.py+++ b/litellm/proxy/db/db_transaction_queue/spend_update_queue.py@@@ -1,5 -1,5 +1,5 @@@import asyncio- from typing import List, Optional-from typing import Dict, List++from typing import Dict, List, Optionalfrom litellm._logging import verbose_proxy_loggerfrom litellm.proxy._types import (