An operator account has team max_budget NULL (no cap). broker_get_usage only assigned balance when max_budget was not None, so the DB path left 'balance' unbound and the HTTP fallback read the same name before assignment — a 500 for exactly the accounts the uncapped policy created. Initialise balance from the member's allowance + credits still available, mark the response uncapped when the team row has no cap, and keep the dashboard arithmetic defined.
This commit is contained in:
1 parent
dc53b27ad2
commit
18a4447aa2
1 file changed
+15
-2
+15
-2
@@ -7681,13 +7681,20 @@ async def broker_get_usage(email: str, days: int = 0) -> dict:
|
|||||||
credits_drawn = get_credits_drawn(email)
|
credits_drawn = get_credits_drawn(email)
|
||||||
spend = 0.0
|
spend = 0.0
|
||||||
reset_at = None
|
reset_at = None
|
||||||
|
# Default: the member's own allowance + credits still available. An
|
||||||
|
# uncapped operator account has no team max_budget (NULL); keep this figure
|
||||||
|
# for the dashboard's arithmetic and say plainly that there is no cap.
|
||||||
|
balance = allowance + max(0.0, credits - credits_drawn)
|
||||||
|
uncapped = False
|
||||||
|
|
||||||
# Fast path: direct Postgres reads.
|
# Fast path: direct Postgres reads.
|
||||||
if litellm_db_ready():
|
if litellm_db_ready():
|
||||||
try:
|
try:
|
||||||
team = get_team_budget_from_db(team_id)
|
team = get_team_budget_from_db(team_id)
|
||||||
if team:
|
if team:
|
||||||
if team["max_budget"] is not None:
|
if team["max_budget"] is None:
|
||||||
|
uncapped = True
|
||||||
|
else:
|
||||||
balance = float(team["max_budget"])
|
balance = float(team["max_budget"])
|
||||||
spend = float(team["spend"] or 0.0)
|
spend = float(team["spend"] or 0.0)
|
||||||
reset_at = team["budget_reset_at"]
|
reset_at = team["budget_reset_at"]
|
||||||
@@ -7732,6 +7739,7 @@ async def broker_get_usage(email: str, days: int = 0) -> dict:
|
|||||||
return {
|
return {
|
||||||
"email": email,
|
"email": email,
|
||||||
"guest": is_guest_account(email),
|
"guest": is_guest_account(email),
|
||||||
|
"uncapped": uncapped,
|
||||||
"balance": balance,
|
"balance": balance,
|
||||||
"allowance": allowance,
|
"allowance": allowance,
|
||||||
"credits": credits,
|
"credits": credits,
|
||||||
@@ -7761,7 +7769,11 @@ async def broker_get_usage(email: str, days: int = 0) -> dict:
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
for t in r.json():
|
for t in r.json():
|
||||||
if t.get("team_id") == team_id:
|
if t.get("team_id") == team_id:
|
||||||
balance = float(t.get("max_budget") or balance)
|
mb = t.get("max_budget")
|
||||||
|
if mb is None:
|
||||||
|
uncapped = True
|
||||||
|
else:
|
||||||
|
balance = float(mb)
|
||||||
spend = float(t.get("spend") or 0.0)
|
spend = float(t.get("spend") or 0.0)
|
||||||
reset_at = t.get("budget_reset_at")
|
reset_at = t.get("budget_reset_at")
|
||||||
break
|
break
|
||||||
@@ -7815,6 +7827,7 @@ async def broker_get_usage(email: str, days: int = 0) -> dict:
|
|||||||
return {
|
return {
|
||||||
"email": email,
|
"email": email,
|
||||||
"guest": is_guest_account(email),
|
"guest": is_guest_account(email),
|
||||||
|
"uncapped": uncapped,
|
||||||
"balance": balance,
|
"balance": balance,
|
||||||
"allowance": allowance,
|
"allowance": allowance,
|
||||||
"credits": credits,
|
"credits": credits,
|
||||||
|
|||||||
Reference in new issue
Block a user