Feat: Add Token Stats and Cost Savings dashboard card and backend tracking

This commit is contained in:
Hitonabi
2026-06-26 13:48:32 +02:00
parent 311f4d7b68
commit 2e4cddc840
9 changed files with 546 additions and 391 deletions
+22
View File
@@ -88,3 +88,25 @@ def self_update() -> dict:
reset = _run(["git", "reset", "--hard", "origin/main"], cwd=SOURCE_DIR)
restart_res = _run(["systemctl", "--user", "restart", "mission-control-2"])
return {"pull": pull, "reset": reset, "restart": restart_res}
from services.token_stats import get_stats
@router.get("/system/token-stats")
def token_stats() -> dict:
stats = get_stats()
p = stats.get("prompt_tokens", 0)
c = stats.get("completion_tokens", 0)
total = p + c
# Blended savings based on a premium cloud model rate (e.g. GPT-4o / Claude 3.5 Sonnet: $3.00/1M input, $15.00/1M output)
saved_usd = (p * 3.0 + c * 15.0) / 1_000_000.0
saved_eur = saved_usd * 0.92 # 1 USD = 0.92 EUR
return {
"prompt_tokens": p,
"completion_tokens": c,
"total_tokens": total,
"saved_usd": round(saved_usd, 2),
"saved_eur": round(saved_eur, 2)
}