Persistent Haiku cost tracking, Sethian whitelist web app

- Haiku cost persists to /var/log/mc_anthropic_cost.json (survives restarts)
- Status printer reads persistent cost file instead of journalctl
- Seeded at $3.08 estimated cumulative spend
- Whitelist app: Sethian Dark theme, mission description, server info

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 22:29:19 -04:00
parent 0473eb0b50
commit 0083e80aca
2 changed files with 298 additions and 8 deletions
+32 -8
View File
@@ -106,8 +106,7 @@ def get_bot_stats():
def get_gemini_usage():
"""Track Gemini API calls. Reads/writes a local JSON counter."""
# Count Gemini calls from bot log
"""Track Gemini API calls from bot log."""
gemini_calls = remote_cmd(f"grep -c 'Gemini.*Generated' {BOT_LOG} 2>/dev/null")
gemini_errors = remote_cmd(f"grep -c 'Gemini.*Error' {BOT_LOG} 2>/dev/null")
@@ -120,7 +119,6 @@ def get_gemini_usage():
except:
errors = 0
# Estimate cost
total_input_tokens = calls * EST_INPUT_TOKENS_PER_CALL
total_output_tokens = calls * EST_OUTPUT_TOKENS_PER_CALL
input_cost = (total_input_tokens / 1_000_000) * GEMINI_INPUT_COST_PER_M
@@ -136,6 +134,21 @@ def get_gemini_usage():
}
def get_haiku_usage():
"""Track Claude Haiku API spend from persistent cost file."""
raw = remote_cmd("cat /var/log/mc_anthropic_cost.json 2>/dev/null")
cost = 0.0
budget = 5.0
if raw and raw.startswith("{"):
try:
import json as _json
data = _json.loads(raw)
cost = data.get("total_cost", 0.0)
except:
pass
return {"cost": cost, "budget": budget}
def get_dataset_size():
"""Get current seed dataset size."""
try:
@@ -195,15 +208,25 @@ def build_receipt():
p.text(f" Last: {last_msg}\n")
p.text("-" * COLS + "\n")
# Gemini API
# Haiku API (main cost)
haiku = get_haiku_usage()
p.set(font='b', align='left', bold=True)
p.text("CLAUDE HAIKU API (dev God)\n")
p.set(font='b', align='left', bold=False)
p.set(font='b', align='left', bold=True)
p.text(f" Spent: ${haiku['cost']:.4f}\n")
p.set(font='b', align='left', bold=False)
p.text(f" Budget: ${haiku['budget']:.2f}\n")
p.text(f" Remaining: ${haiku['budget'] - haiku['cost']:.4f}\n")
p.text("-" * COLS + "\n")
# Gemini API (bot prompts)
gemini = get_gemini_usage()
p.set(font='b', align='left', bold=True)
p.text("GEMINI API (flash-lite)\n")
p.text("GEMINI API (bot prompts)\n")
p.set(font='b', align='left', bold=False)
p.text(f" Calls: {gemini['calls']}\n")
p.text(f" Errors: {gemini['errors']}\n")
p.text(f" Est input tokens: {gemini['est_input_tokens']:,}\n")
p.text(f" Est output tokens: {gemini['est_output_tokens']:,}\n")
p.set(font='b', align='left', bold=True)
p.text(f" Est cost: ${gemini['est_cost_usd']:.4f}\n")
p.set(font='b', align='left', bold=False)
@@ -278,6 +301,7 @@ def main():
dataset_size = get_dataset_size()
dev_audit, prod_audit, bug_count = get_audit_stats()
num_bots, num_sends, last_msg = get_bot_stats()
haiku = get_haiku_usage()
statuses = get_service_status()
print(f"Dataset: {dataset_size} seed examples")
@@ -285,9 +309,9 @@ def main():
print(f"Prod audit: {prod_audit} entries")
print(f"Bug reports: {bug_count}")
print(f"Bots: {num_bots} active, {num_sends} messages sent")
print(f"Haiku: ${haiku['cost']:.4f} / ${haiku['budget']:.2f} ({haiku['budget'] - haiku['cost']:.4f} remaining)")
print(f"Gemini: {gemini['calls']} calls, {gemini['errors']} errors, ${gemini['est_cost_usd']:.4f}")
print(f"Services: {statuses}")
print(f"Threshold: ${COST_PRINT_THRESHOLD} (would print: {should_print(current_cost) or force})")
return
if not force and not should_print(current_cost):