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]

fix _reset_budget_for_team

Ishaan Jaffa9123d961d41
diff --git a/litellm/proxy/common_utils/reset_budget_job.py b/litellm/proxy/common_utils/reset_budget_job.py
index 6a1842fc134..1d50002f5cf 100644
--- a/litellm/proxy/common_utils/reset_budget_job.py
+++ b/litellm/proxy/common_utils/reset_budget_job.py
@@ -2,7 +2,7 @@ import asyncio
import json
import time
from datetime import datetime, timedelta
-from typing import List, Optional, Union
+from typing import List, Literal, Optional, Union
from litellm._logging import verbose_proxy_logger
from litellm.litellm_core_utils.duration_parser import duration_in_seconds
@@ -318,9 +318,11 @@ class ResetBudgetJob:
async def _reset_budget_common(
item: Union[LiteLLM_TeamTable, LiteLLM_UserTable, LiteLLM_VerificationToken],
current_time: datetime,
- item_type: str,
+ item_type: Literal["key", "team", "user"],
):
"""
+ In-place, updates spend=0, and sets budget_reset_at to current_time + budget_duration
+
Common logic for resetting budget for a team, user, or key
"""
try:
@@ -339,19 +341,25 @@ class ResetBudgetJob:
async def _reset_budget_for_team(
team: LiteLLM_TeamTable, current_time: datetime
) -> Optional[LiteLLM_TeamTable]:
- await ResetBudgetJob._reset_budget_common(team, current_time, "team")
+ await ResetBudgetJob._reset_budget_common(
+ item=team, current_time=current_time, item_type="team"
+ )
return team
@staticmethod
async def _reset_budget_for_user(
user: LiteLLM_UserTable, current_time: datetime
) -> Optional[LiteLLM_UserTable]:
- await ResetBudgetJob._reset_budget_common(user, current_time, "user")
+ await ResetBudgetJob._reset_budget_common(
+ item=user, current_time=current_time, item_type="user"
+ )
return user
@staticmethod
async def _reset_budget_for_key(
key: LiteLLM_VerificationToken, current_time: datetime
) -> Optional[LiteLLM_VerificationToken]:
- await ResetBudgetJob._reset_budget_common(key, current_time, "key")
+ await ResetBudgetJob._reset_budget_common(
+ item=key, current_time=current_time, item_type="key"
+ )
return key