From bb5e71447dabfd94ce6277478419a1402dc03631 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 13 Sep 2025 18:15:34 -0700 Subject: [PATCH] fix(spend_management_endpoints.py): add end user filtering --- litellm/constants.py | 2 +- .../spend_tracking/spend_management_endpoints.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index e40f1a5da2d..c0ce0f265b5 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -15,7 +15,7 @@ DEFAULT_SQS_FLUSH_INTERVAL_SECONDS = int( os.getenv("DEFAULT_SQS_FLUSH_INTERVAL_SECONDS", 10) ) DEFAULT_NUM_WORKERS_LITELLM_PROXY = int( - os.getenv("DEFAULT_NUM_WORKERS_LITELLM_PROXY", 4) + os.getenv("DEFAULT_NUM_WORKERS_LITELLM_PROXY", 1) ) DEFAULT_SQS_BATCH_SIZE = int(os.getenv("DEFAULT_SQS_BATCH_SIZE", 512)) SQS_SEND_MESSAGE_ACTION = "SendMessage" diff --git a/litellm/proxy/spend_tracking/spend_management_endpoints.py b/litellm/proxy/spend_tracking/spend_management_endpoints.py index e7d28bc317f..16985d76b33 100644 --- a/litellm/proxy/spend_tracking/spend_management_endpoints.py +++ b/litellm/proxy/spend_tracking/spend_management_endpoints.py @@ -10,7 +10,6 @@ from fastapi import APIRouter, Depends, HTTPException, status import litellm from litellm._logging import verbose_proxy_logger -from litellm.router_strategy.budget_limiter import RouterBudgetLimiting from litellm.proxy._types import * from litellm.proxy._types import ProviderBudgetResponse, ProviderBudgetResponseObject from litellm.proxy.auth.user_api_key_auth import user_api_key_auth @@ -18,6 +17,7 @@ from litellm.proxy.spend_tracking.spend_tracking_utils import ( get_spend_by_team_and_customer, ) from litellm.proxy.utils import handle_exception_on_proxy +from litellm.router_strategy.budget_limiter import RouterBudgetLimiting if TYPE_CHECKING: from litellm.proxy.proxy_server import PrismaClient @@ -1663,6 +1663,9 @@ async def ui_view_spend_logs( # noqa: PLR0915 key_alias: Optional[str] = fastapi.Query( default=None, description="Filter logs by key alias" ), + end_user: Optional[str] = fastapi.Query( + default=None, description="Filter logs by end user" + ), ): """ View spend logs for UI with pagination support @@ -1730,13 +1733,16 @@ async def ui_view_spend_logs( # noqa: PLR0915 if model is not None: where_conditions["model"] = model - + if key_alias is not None: where_conditions["metadata"] = { "path": ["user_api_key_alias"], - "string_contains": key_alias + "string_contains": key_alias, } + if end_user is not None: + where_conditions["end_user"] = end_user + if min_spend is not None or max_spend is not None: where_conditions["spend"] = {} if min_spend is not None: