Skip to content

feat(report): API cost estimation overlay (Phase 3 M6)#9

Merged
rojae merged 1 commit into
feature/phase3/basefrom
feature/phase3/cost
Apr 30, 2026
Merged

feat(report): API cost estimation overlay (Phase 3 M6)#9
rojae merged 1 commit into
feature/phase3/basefrom
feature/phase3/cost

Conversation

@rojae

@rojae rojae commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the README "Usage tracker" 🟡 → ✅ by adding a cost overlay across every report surface.

  • Pricing table (crates/fluxmirror-core/src/cost/mod.rs): Claude Opus 4.7 / Sonnet 4.6 / Haiku 4.5, OpenAI GPT-4-Turbo / GPT-4o, Google Gemini 2.5 Pro / Flash. Source URLs cited per entry.
  • Token extraction: parses Anthropic-shaped `usage` blocks out of `events.message_json` for MCP traffic.
  • Heuristic fallback: Gemini / Qwen rows in `agent_events` get `len(detail) * 1.3 / 4` token estimates, flagged via `AgentCost.estimate` / `ModelCost.estimate`.
  • Wired into: text today/week reports (`## Cost` section), Phase 2 weekly HTML card (cost row in summary), studio `/api/today` + `/api/week` JSON, studio Today + Week pages with footnote when `estimate_share > 0`.
  • Capture binary unchanged.

Files

12 modified + 4 new (cost module, pricing-sources doc, CostBlock component, CLI cost.rs).

Test plan

  • `cargo test --workspace --no-fail-fast` — all green (140 unit + 127 integration in CLI)
  • `pnpm build` in studio-web/ — green
  • Workspace builds clean with `-D warnings`

Token usage parsed from MCP events.message_json (Anthropic-shaped
usage block) plus a length-based heuristic estimate for non-MCP
agents. Static pricing table covers Claude (Opus 4.7 / Sonnet 4.6 /
Haiku 4.5), OpenAI (GPT-4-Turbo / GPT-4o), Google (Gemini 2.5 Pro /
Flash). Source URLs cited per entry; quarterly refresh tracked in
docs/PRICING_SOURCES.md.

CostSummary lands on every output surface — text today/week
reports get a `## Cost` section, the Phase 2 weekly HTML card shows
a cost row, and studio /api/today + /api/week JSON gain a
`cost: CostSummary` field. The estimate_share fraction lights up a
"estimate" footnote on the studio Today + Week pages so guessed
figures never silently masquerade as exact.

Heuristic agents (Gemini / Qwen) compute tokens as
len(detail) * 1.3 / 4 with output ≈ 2 * input — flagged via
AgentCost.estimate / ModelCost.estimate. Capture binary unchanged.
@rojae rojae merged commit 0d83368 into feature/phase3/base Apr 30, 2026
2 of 3 checks passed
@rojae rojae deleted the feature/phase3/cost branch April 30, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant