mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
(feat) alert for failing cost tracking
This commit is contained in:
parent
4cb7759fcd
commit
8462e85792
2 changed files with 30 additions and 2 deletions
|
@ -852,8 +852,20 @@ async def _PROXY_track_cost_callback(
|
||||||
f"Model not in litellm model cost map. Add custom pricing - https://docs.litellm.ai/docs/proxy/custom_pricing"
|
f"Model not in litellm model cost map. Add custom pricing - https://docs.litellm.ai/docs/proxy/custom_pricing"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
error_msg = f"error in tracking cost callback - {traceback.format_exc()}"
|
||||||
|
error_msg += f"\n Args to _PROXY_track_cost_callback\n kwargs: {kwargs}\n completion_response: {completion_response}"
|
||||||
|
user_id = user_id or "not-found"
|
||||||
|
asyncio.create_task(
|
||||||
|
proxy_logging_obj.budget_alerts(
|
||||||
|
user_max_budget=0,
|
||||||
|
user_current_spend=0,
|
||||||
|
type="failed_tracking",
|
||||||
|
user_info=user_id,
|
||||||
|
error_message=error_msg,
|
||||||
|
)
|
||||||
|
)
|
||||||
verbose_proxy_logger.debug(
|
verbose_proxy_logger.debug(
|
||||||
f"error in tracking cost callback - {traceback.format_exc}"
|
f"error in tracking cost callback - {traceback.format_exc()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -198,10 +198,17 @@ class ProxyLogging:
|
||||||
|
|
||||||
async def budget_alerts(
|
async def budget_alerts(
|
||||||
self,
|
self,
|
||||||
type: Literal["token_budget", "user_budget", "user_and_proxy_budget"],
|
type: Literal[
|
||||||
|
"token_budget",
|
||||||
|
"user_budget",
|
||||||
|
"user_and_proxy_budget",
|
||||||
|
"failed_budgets",
|
||||||
|
"failed_tracking",
|
||||||
|
],
|
||||||
user_max_budget: float,
|
user_max_budget: float,
|
||||||
user_current_spend: float,
|
user_current_spend: float,
|
||||||
user_info=None,
|
user_info=None,
|
||||||
|
error_message="",
|
||||||
):
|
):
|
||||||
if self.alerting is None:
|
if self.alerting is None:
|
||||||
# do nothing if alerting is not switched on
|
# do nothing if alerting is not switched on
|
||||||
|
@ -221,6 +228,15 @@ class ProxyLogging:
|
||||||
max_budget = token_info["max_budget"]
|
max_budget = token_info["max_budget"]
|
||||||
user_id = token_info["user_id"]
|
user_id = token_info["user_id"]
|
||||||
user_info = f"""\nToken: {token}\nSpend: ${spend}\nMax Budget: ${max_budget}\nUser ID: {user_id}"""
|
user_info = f"""\nToken: {token}\nSpend: ${spend}\nMax Budget: ${max_budget}\nUser ID: {user_id}"""
|
||||||
|
elif type == "failed_tracking":
|
||||||
|
user_id = str(user_info)
|
||||||
|
user_info = f"\nUser ID: {user_id}\n Error {error_message}"
|
||||||
|
message = "Failed Tracking Cost for" + user_info
|
||||||
|
await self.alerting_handler(
|
||||||
|
message=message,
|
||||||
|
level="High",
|
||||||
|
)
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
user_info = str(user_info)
|
user_info = str(user_info)
|
||||||
# percent of max_budget left to spend
|
# percent of max_budget left to spend
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue