spend: name the unattributed slice of own spend for posterity

own_all_time_spend already includes SpendLogs rows that join to no team alias,
but the remainder was unnamed, so every reader had to notice it by subtraction.
coop_spend_totals() now reports own_unattributed_spend and both payloads
(/admin/overview totals and admin/money-series totals) carry it: the gateway's
own overhead, historically the master-key audio keepalive pings (~$3.21 over
16,894 rows before the 2026-11-28 key split).

History is labelled, never rewritten: LiteLLM_SpendLogs is the system of record
and the portal keeps read-only access, so no team_id is backfilled.
This commit is contained in:
inference-admin committed 2026-11-28 14:03:47 +00:00
1 parent aba53eabb5
commit 1191bcd521
2 files changed
+20 -3

No files matched your search

+16 -3
View File
@@ -6590,11 +6590,15 @@ async def admin_overview(request: Request):
"operator_all_time_spend": round(operator_all_time, 2), "operator_all_time_spend": round(operator_all_time, 2),
# The co-op's spend, the ONE definition both apps show (see # The co-op's spend, the ONE definition both apps show (see
# coop_spend_totals). spend_all_time spans members AND the co-op's # coop_spend_totals). spend_all_time spans members AND the co-op's
# own accounts; own_all_time_spend is the breakout. # own accounts; own_all_time_spend is the breakout, and
# own_unattributed_spend names the part of it that joins to no team
# alias (gateway overhead — historically the master-key keepalive
# pings, kept as history rather than rewritten).
**{ **{
k: v k: v
for k, v in _coop_spend_totals_safe().items() for k, v in _coop_spend_totals_safe().items()
if k in ("spend_all_time", "own_all_time_spend") if k in ("spend_all_time", "own_all_time_spend",
"own_unattributed_spend")
}, },
}, },
} }
@@ -6850,6 +6854,11 @@ def coop_spend_totals() -> dict:
as litellm_spend_by_day(), so the cards and the money chart agree. as litellm_spend_by_day(), so the cards and the money chart agree.
own = the co-op's own use: every team that is not a member team, plus rows own = the co-op's own use: every team that is not a member team, plus rows
with no team at all (nothing here is a member's usage). with no team at all (nothing here is a member's usage).
unattributed = the part of own that joins to NO team alias (empty alias).
Named so it is auditable rather than a silent remainder: historically
the audio keepalive pings on the master key, ~$3.21 over 16,894 rows
before the key split on 2026-11-28. Never rewritten in LiteLLM's
tables — that table is the system of record and is read-only here.
""" """
if not litellm_db_ready(): if not litellm_db_ready():
raise RuntimeError("LiteLLM DB credentials not configured") raise RuntimeError("LiteLLM DB credentials not configured")
@@ -6866,7 +6875,7 @@ def coop_spend_totals() -> dict:
rows = cur.fetchall() rows = cur.fetchall()
finally: finally:
conn.close() conn.close()
member = own = 0.0 member = own = unattributed = 0.0
aliases = 0 aliases = 0
for alias, spend in rows: for alias, spend in rows:
val = float(spend or 0.0) val = float(spend or 0.0)
@@ -6875,10 +6884,13 @@ def coop_spend_totals() -> dict:
member += val member += val
else: else:
own += val own += val
if not str(alias or "").strip():
unattributed += val
return { return {
"spend_all_time": round(member + own, 2), "spend_all_time": round(member + own, 2),
"member_all_time_spend": round(member, 2), "member_all_time_spend": round(member, 2),
"own_all_time_spend": round(own, 2), "own_all_time_spend": round(own, 2),
"own_unattributed_spend": round(unattributed, 2),
"aliases": aliases, "aliases": aliases,
} }
@@ -7012,6 +7024,7 @@ async def _compute_money_payload() -> dict:
# The member-owned vs co-op's-own split of that same all-time spend, # The member-owned vs co-op's-own split of that same all-time spend,
# from the one shared definition. # from the one shared definition.
"own_all_time_spend": (_coop_split := _coop_spend_totals_safe()).get("own_all_time_spend"), "own_all_time_spend": (_coop_split := _coop_spend_totals_safe()).get("own_all_time_spend"),
"own_unattributed_spend": _coop_split.get("own_unattributed_spend"),
"member_all_time_spend": _coop_split.get("member_all_time_spend"), "member_all_time_spend": _coop_split.get("member_all_time_spend"),
}, },
"sources": { "sources": {
+4
View File
@@ -77,6 +77,10 @@ try:
f"member side is the member: teams ($10.005 + $5.005 -> 15.01, got {t['member_all_time_spend']})") f"member side is the member: teams ($10.005 + $5.005 -> 15.01, got {t['member_all_time_spend']})")
check(t["own_all_time_spend"] == 2.59, check(t["own_all_time_spend"] == 2.59,
f"own side is everything else: agents, sandboxes, unattributed (got {t['own_all_time_spend']})") f"own side is everything else: agents, sandboxes, unattributed (got {t['own_all_time_spend']})")
check(t["own_unattributed_spend"] == 1.07,
f"rows that join to no team alias are named, not left as a silent remainder (got {t['own_unattributed_spend']})")
check(t["own_unattributed_spend"] <= t["own_all_time_spend"],
"unattributed is a part of own, never added on top of the total")
check(t["spend_all_time"] == round(t["member_all_time_spend"] + t["own_all_time_spend"], 2), check(t["spend_all_time"] == round(t["member_all_time_spend"] + t["own_all_time_spend"], 2),
"total == member + own, so no dollar is counted twice or dropped") "total == member + own, so no dollar is counted twice or dropped")
check(t["spend_all_time"] == round(sum(r[1] for r in ROWS), 2), check(t["spend_all_time"] == round(sum(r[1] for r in ROWS), 2),