Build cost tracking and budget enforcement #97

Open
opened 2026-03-30 15:40:27 +00:00 by Timmy · 2 comments
Owner

Objective

Track every cloud API call's cost and enforce daily/monthly budgets. Timmy should know exactly how much cognition he's renting and stay within Alexander's budget.

Parent Epic

#94 — Grand Timmy: The Uniwizard

Implementation

Cost Tracking

Every cloud call logs:

{
    "timestamp": "2026-04-01T10:30:00Z",
    "backend": "claude",
    "model": "claude-sonnet-4-20250514",
    "prompt_tokens": 1500,
    "completion_tokens": 800,
    "cost_usd": 0.0069,
    "task_id": "issue-94",
    "task_type": "reasoning",
    "duration_ms": 3200
}

Budget Enforcement

budgets:
  daily_limit_usd: 5.00
  monthly_limit_usd: 50.00
  per_backend:
    claude: 20.00/month
    kimi: 15.00/month
    gpt: 10.00/month
    gemini: 5.00/month
  warning_threshold: 0.8  # warn at 80% spend
  hard_stop: true  # refuse cloud calls at limit

When Budget Exceeded

  • Timmy falls back to local for everything
  • Posts a notice: "Cloud budget exhausted, operating local-only until {reset_date}"
  • Never silently fails

In Evennia

  • costs command shows today's spend, month's spend, per-backend
  • budget command shows limits and remaining
  • Observatory room displays cost dashboard
  • Alert Script warns when approaching limits

Deliverables

  • agent/cost_tracker.py — per-call cost logging
  • agent/budget.py — enforcement logic
  • configs/budgets.yaml — budget configuration
  • commands/costs.py — Evennia commands
  • SQLite table for cost history

Acceptance Criteria

  • Every cloud call logged with cost
  • Daily and monthly totals accurate
  • Hard stop works (blocks cloud calls at limit)
  • Timmy degrades to local-only gracefully
  • Cost history queryable (show me last week's spend)
## Objective Track every cloud API call's cost and enforce daily/monthly budgets. Timmy should know exactly how much cognition he's renting and stay within Alexander's budget. ## Parent Epic #94 — Grand Timmy: The Uniwizard ## Implementation ### Cost Tracking Every cloud call logs: ```json { "timestamp": "2026-04-01T10:30:00Z", "backend": "claude", "model": "claude-sonnet-4-20250514", "prompt_tokens": 1500, "completion_tokens": 800, "cost_usd": 0.0069, "task_id": "issue-94", "task_type": "reasoning", "duration_ms": 3200 } ``` ### Budget Enforcement ```yaml budgets: daily_limit_usd: 5.00 monthly_limit_usd: 50.00 per_backend: claude: 20.00/month kimi: 15.00/month gpt: 10.00/month gemini: 5.00/month warning_threshold: 0.8 # warn at 80% spend hard_stop: true # refuse cloud calls at limit ``` ### When Budget Exceeded - Timmy falls back to local for everything - Posts a notice: "Cloud budget exhausted, operating local-only until {reset_date}" - Never silently fails ### In Evennia - `costs` command shows today's spend, month's spend, per-backend - `budget` command shows limits and remaining - Observatory room displays cost dashboard - Alert Script warns when approaching limits ## Deliverables - `agent/cost_tracker.py` — per-call cost logging - `agent/budget.py` — enforcement logic - `configs/budgets.yaml` — budget configuration - `commands/costs.py` — Evennia commands - SQLite table for cost history ## Acceptance Criteria - [ ] Every cloud call logged with cost - [ ] Daily and monthly totals accurate - [ ] Hard stop works (blocks cloud calls at limit) - [ ] Timmy degrades to local-only gracefully - [ ] Cost history queryable (show me last week's spend)
ezra was assigned by Timmy 2026-03-30 15:40:27 +00:00
Owner

Reframe: Budget Enforcement → Quota Utilization Tracking

Per Alexander's directive: the money is already spent. ~$500/month across backends. Unused quota = wasted money.

This issue should flip from "don't overspend" to "are we USING what we're paying for?"

Alerts should fire on:

  • Backend at <50% utilization mid-cycle → route more work there
  • Backend approaching 0% remaining → gracefully shift load, don't panic
  • Total utilization across all backends <70% → Timmy is being too conservative

The ceiling matters. The floor matters MORE.

## Reframe: Budget Enforcement → Quota Utilization Tracking Per Alexander's directive: the money is already spent. ~$500/month across backends. Unused quota = wasted money. This issue should flip from "don't overspend" to "are we USING what we're paying for?" Alerts should fire on: - Backend at <50% utilization mid-cycle → route more work there - Backend approaching 0% remaining → gracefully shift load, don't panic - Total utilization across all backends <70% → Timmy is being too conservative The ceiling matters. The floor matters MORE.
Author
Owner

Role Transition

Timmy now owns execution — building, coding, implementing.
Ezra moves to persistent online ops — monitoring, triage, review, cron, 24/7 watchkeeping.

Timmy: this is yours. Read the ticket, build it, PR it. Ezra reviews.

Timmy — build cost tracking. Log every cloud API call with token counts and cost. Enforce daily/monthly budgets. Fall back to local when budget exhausted.

## Role Transition **Timmy** now owns execution — building, coding, implementing. **Ezra** moves to persistent online ops — monitoring, triage, review, cron, 24/7 watchkeeping. Timmy: this is yours. Read the ticket, build it, PR it. Ezra reviews. Timmy — build cost tracking. Log every cloud API call with token counts and cost. Enforce daily/monthly budgets. Fall back to local when budget exhausted.
ezra was unassigned by Timmy 2026-03-30 16:03:23 +00:00
Timmy self-assigned this 2026-03-30 16:03:23 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Timmy_Foundation/timmy-home#97