diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index edb5c6970f..409cf63d55 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1241,17 +1241,16 @@ async def update_database( f"_update_team_db: existing spend: {existing_spend_obj}" ) if existing_spend_obj is None: - existing_spend = 0 + # the team does not exist in the db - return + verbose_proxy_logger.debug( + "team_id does not exist in db, not tracking spend for team" + ) + return else: existing_spend = existing_spend_obj.spend # Calculate the new cost by adding the existing cost and response_cost new_spend = existing_spend + response_cost - - if existing_spend_obj is None: - spend_per_model = {} - else: - spend_per_model = existing_spend_obj.model_spend or {} - + spend_per_model = getattr(existing_spend_obj, "model_spend", {}) # track cost per model, for the given team spend_per_model = existing_spend_obj.model_spend or {} current_model = kwargs.get("model")