Expose credits_remaining (purchased minus cycle overspend) in broker usage + admin overview

This commit is contained in:
inference-bot committed 2026-10-03 13:59:29 -06:00
1 parent 052a109040
commit 38005127cb
1 file changed
+10 -1
+10 -1
View File
@@ -589,11 +589,15 @@ def compute_max_budget(allowance: float, credit_balance: float, team_spend: floa
allowance. The total spendable cap is simply `allowance + credit_balance`
— credits never shrink the allowance; they extend it.
`credit_balance` is the TOTAL purchased (the ledger's lifetime sum); the
amount still available this cycle is `credit_balance - credits_used`.
`team_spend` is the member's spend so far this cycle (from LiteLLM). It is
used only to split the spend between allowance vs credits for display, NOT
to reduce the cap.
Returns {"max_budget", "allowance_used", "credits_used"} for dashboards.
Returns {"max_budget", "allowance_used", "credits_used", "credits_remaining"}
for dashboards.
"""
max_budget = allowance + credit_balance
if team_spend is None:
@@ -601,6 +605,7 @@ def compute_max_budget(allowance: float, credit_balance: float, team_spend: floa
"max_budget": max_budget,
"allowance_used": 0.0,
"credits_used": 0.0,
"credits_remaining": credit_balance,
}
allowance_used = min(max(team_spend, 0.0), allowance)
credits_used = max(0.0, team_spend - allowance)
@@ -608,6 +613,7 @@ def compute_max_budget(allowance: float, credit_balance: float, team_spend: floa
"max_budget": max_budget,
"allowance_used": allowance_used,
"credits_used": credits_used,
"credits_remaining": max(0.0, credit_balance - credits_used),
}
@@ -2170,6 +2176,7 @@ async def admin_overview(request: Request):
"manual": email.lower() in MANUAL_MEMBERS,
"balance": float(balance) if balance is not None else MEMBER_BUDGET,
"credit_balance": credits,
"credits_remaining": max(0.0, credits - eff["credits_used"]),
"allowance_used": eff["allowance_used"],
"credits_used": eff["credits_used"],
"spend": spend,
@@ -2469,6 +2476,7 @@ async def broker_get_usage(email: str, days: int = 0) -> dict:
"balance": balance,
"allowance": allowance,
"credits": credits,
"credits_remaining": max(0.0, credits - max(0.0, spend - allowance)),
"spend": spend,
"all_time_spend": round(all_time_spend, 2),
"remaining": max(balance - spend, 0.0),
@@ -2541,6 +2549,7 @@ async def broker_get_usage(email: str, days: int = 0) -> dict:
"balance": balance,
"allowance": allowance,
"credits": credits,
"credits_remaining": max(0.0, credits - max(0.0, spend - allowance)),
"spend": spend,
"all_time_spend": all_time_spend,
"remaining": max(balance - spend, 0.0),