UI update changed
This commit is contained in:
@@ -453,13 +453,12 @@ class BillingLedger:
|
||||
with self._lock:
|
||||
return self._node_pending.get(wallet, 0.0)
|
||||
|
||||
def usage_for(self, api_keys: list[str], *, recent_limit: int | None = None) -> dict:
|
||||
"""Aggregate charge history for a set of API keys (dashboard view)."""
|
||||
def usage_totals_for(self, api_keys: list[str]) -> dict:
|
||||
"""Aggregate charge totals without per-request records (dashboard summary)."""
|
||||
keys = set(api_keys)
|
||||
requests = 0
|
||||
total_tokens = 0
|
||||
total_cost = 0.0
|
||||
records: list[dict] = []
|
||||
with self._lock:
|
||||
for event in self._event_log:
|
||||
if event.get("type") != "charge" or event.get("api_key") not in keys:
|
||||
@@ -467,6 +466,20 @@ class BillingLedger:
|
||||
requests += 1
|
||||
total_tokens += int(event.get("total_tokens", 0))
|
||||
total_cost += float(event.get("cost", 0.0))
|
||||
return {
|
||||
"requests": requests,
|
||||
"total_tokens": total_tokens,
|
||||
"total_cost": total_cost,
|
||||
}
|
||||
|
||||
def usage_for(self, api_keys: list[str], *, recent_limit: int | None = None) -> dict:
|
||||
"""Aggregate charge history for a set of API keys (dashboard view)."""
|
||||
keys = set(api_keys)
|
||||
records: list[dict] = []
|
||||
with self._lock:
|
||||
for event in self._event_log:
|
||||
if event.get("type") != "charge" or event.get("api_key") not in keys:
|
||||
continue
|
||||
records.append({
|
||||
"api_key": event["api_key"],
|
||||
"model": event.get("model"),
|
||||
@@ -476,9 +489,9 @@ class BillingLedger:
|
||||
})
|
||||
recent = records[-recent_limit:] if recent_limit is not None else records
|
||||
return {
|
||||
"requests": requests,
|
||||
"total_tokens": total_tokens,
|
||||
"total_cost": total_cost,
|
||||
"requests": len(records),
|
||||
"total_tokens": sum(int(r.get("total_tokens", 0)) for r in records),
|
||||
"total_cost": sum(float(r.get("cost", 0.0)) for r in records),
|
||||
"records": records,
|
||||
"recent": recent,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user