Cost Tracking
CostTrackingService records token usage and computes estimated cost for every LLM call. Per-model pricing tables for 30+ models. Now cache-aware (as of 2026-07-10) — Anthropic prompt-cache reads are priced separately at their lower rate.
What it tracks
Section titled “What it tracks”Per call:
- Input tokens — prompt + context sent to the model
- Output tokens — model response
- Cache read — tokens served from the provider’s prompt cache (Anthropic)
- Cache creation — first-time cache writes (Anthropic)
- Estimated cost — 6-decimal precision
Cost is a weighted sum:
cost = uncached_input × input_rate + cache_read × cache_read_rate (Anthropic) + cache_creation × cache_creation_rate (Anthropic) + output × output_rateAll rates per million tokens.
Viewing costs
Section titled “Viewing costs”- Per message — token count under each response
- Per conversation — cumulative cost for the current thread
- Aggregate summary — breakdown by provider + model
Spend limits
Section titled “Spend limits”{ "codebuddy.agent.costThreshold": 1000, "codebuddy.agent.costThresholdWarningPercent": 80, "codebuddy.agent.dailySpendCap": null}codebuddy.agent.costThreshold— maximum spend (USD) per conversation before CodeBuddy pauses and asks whether to continue. Default1000.codebuddy.agent.costThresholdWarningPercent— percentage of the threshold at which a warning is shown (1–99). Default80.codebuddy.agent.dailySpendCap— maximum total daily spend (USD) across all conversations.nulldisables it.
Pricing (approximate, mid-2025)
Section titled “Pricing (approximate, mid-2025)”Per million tokens.
| Provider | Model | Input | Output |
|---|---|---|---|
| Anthropic | Claude Sonnet 4 | $3.00 | $15.00 |
| Anthropic | Claude Opus 4 | $15.00 | $75.00 |
| Anthropic | Claude Haiku | $0.25 | $1.25 |
| OpenAI | GPT-4o | $2.50 | $10.00 |
| OpenAI | GPT-4o-mini | $0.15 | $0.60 |
| OpenAI | o3-mini | $1.10 | $4.40 |
| Gemini 2.5 Pro | $1.25 | $10.00 | |
| Gemini 2.5 Flash | $0.15 | $0.60 | |
| Groq | Llama 3.3 70B | $0.59 | $0.79 |
| DeepSeek | DeepSeek Chat | $0.27 | $1.10 |
| DeepSeek | DeepSeek Reasoner | $0.55 | $2.19 |
| Qwen | Qwen Plus | $0.80 | $2.00 |
| xAI | Grok | $5.00 | $15.00 |
| Ollama | Local models | Free | Free |
When a model isn’t in the pricing table, conservative fallback: $3.00 / $15.00 per million.
Anthropic cache rates live in the same table under separate columns (cacheReadPerMillion, cacheCreationPerMillion) — see cost-tracking.service.ts for exact numbers.
Cost summary shape
Section titled “Cost summary shape”interface ICostSummary { totals: { inputTokens: number; outputTokens: number; cacheReadTokens?: number; cacheCreationTokens?: number; estimatedCost: number; requestCount: number; }; providers: Array<{ provider: string; model: string; inputTokens: number; outputTokens: number; cacheReadTokens?: number; estimatedCost: number; requestCount: number; }>; conversations: Array<{ threadId: string; provider: string; model: string; inputTokens: number; outputTokens: number; estimatedCost: number; requestCount: number; }>;}Reducing spend
Section titled “Reducing spend”- Smaller models for simple tasks — GPT-4o-mini or Gemini Flash for renames, formatting, trivial edits.
- Local models — Ollama for tasks that don’t need frontier intelligence.
- Project rules — clear rules reduce iteration.
codebuddy.agent.costThreshold/dailySpendCap— per-conversation and daily USD safety nets.- Anthropic prompt caching — already active; hit rate ~99% on turn 2+. Long conversations become cheap.
- Start fresh conversations for unrelated tasks — old context doesn’t help and costs tokens.