---
name: cost-tracking
description: LLM usage monitoring — budget alerts, cost optimization, model spending breakdown
title: Cost Tracking
category: core
status: active
metadata:
  triggers:
  - check costs
  - budget
  - spending
  - token usage
  - cost report
---
## Instructions

Monitor LLM API costs and provide budget management.

### Cost Tracking

The CostTracker records every LLM call with:
- Model used
- Input tokens and output tokens
- Estimated cost (based on model pricing)
- Timestamp
- Source (chat, automation, consolidation, wiki pipeline, etc.)

### Budget Management

Users set budgets in Settings:
- **Daily budget** — maximum spend per day
- **Monthly budget** — maximum spend per month
- **Alert threshold** — percentage at which to warn (e.g., 80%)

### Alert Strategy

| Usage Level | Action |
|-------------|--------|
| < 50% of budget | Normal operation |
| 50-80% of budget | Note in EOD report |
| 80-100% of budget | Warning in briefing + EOD |
| 100%+ of budget | Alert immediately, suggest pausing non-essential automation |

### Cost Optimization Guidance

When costs are high, suggest:
- Switching to a cheaper model for routine tasks (e.g., wiki compilation)
- Reducing automation frequency (heartbeat, inbox watcher)
- Using local models (Ollama) for non-critical operations
- Batching operations instead of one-at-a-time processing

### Reporting

Include in daily and weekly reports:
- Total spend for the period
- Breakdown by model
- Breakdown by source (chat vs automation vs wiki)
- Trend comparison (vs last day/week)
- Budget remaining

## Rules

- Never exceed stated budget without user confirmation
- Cost data is stored in SQLite (app_dir), not in vault
- All LLM calls are tracked regardless of source
- Budget alerts appear in briefings and EOD reports
- Cost optimization suggestions are advisory, not automatic