Skip to content

fix(analytics): expose flat-rate estimates on cost dashboards - #11460

Draft
xiaoyaner0201 wants to merge 3 commits into
diegosouzapw:release/v3.8.51from
xiaoyaner0201:fix/11459-cc-cost-estimates
Draft

fix(analytics): expose flat-rate estimates on cost dashboards#11460
xiaoyaner0201 wants to merge 3 commits into
diegosouzapw:release/v3.8.51from
xiaoyaner0201:fix/11459-cc-cost-estimates

Conversation

@xiaoyaner0201

@xiaoyaner0201 xiaoyaner0201 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #11459.

Claude Code (claude / cc) is correctly classified as a flat-rate subscription, so the analytics API reports $0 by default. The Costs and Analytics dashboards are estimate-oriented views, but neither originally had a token-price-equivalent view of subscription consumption.

This change preserves both meanings:

  • ordinary analytics callers keep billed-cost semantics ($0 for flat-rate subscriptions);
  • /dashboard/costs and /dashboard/analytics explicitly request token-price-equivalent estimates;
  • the response reports whether estimates were included, so callers cannot mistake them for vendor billing records.

The defect is confirmed on the latest release/v3.8.50 line. This PR targets the active release/v3.8.51 branch because #11439 freezes v3.8.50.

Changes

  • Add the exact opt-in query contract includeFlatRateEstimates=true; omitted, false, and unknown values retain the existing $0 behavior.
  • Make both cost visualization pages request estimate mode and expose includesFlatRateEstimates in the response.
  • Apply the selected mode consistently to summary, daily trend, model/provider/account/API-key breakdowns, service-tier comparison, and preset summaries.
  • Keep rollups estimate-capable after raw-history retention and group cost inputs at day/provider/model/service-tier granularity so non-linear pricing clamps reconcile across summary and breakdowns.
  • Add regression coverage for default and estimate modes, archived usage, rollup persistence, aggregation consistency, and both dashboard wiring paths.

Non-goals

  • No change to budgets, quota enforcement, routing, stored credentials, or provider billing semantics.
  • Estimates are not presented as actual subscription invoices or vendor billing data.
  • This PR does not address the separate analytics-page latency issue.

Testing

  • ✅ RED wiring test failed before the Analytics overview opt-in was added.
  • node --import tsx/esm --test tests/integration/integration-wiring.test.ts tests/unit/usage-analytics-route.test.ts tests/unit/flat-rate-cost-5552.test.ts tests/unit/usage-analytics.test.ts tests/unit/db-usageanalytics-split.test.ts tests/unit/db-usageanalytics-sources-split.test.ts — 148 tests, 144 passed / 4 skipped / 0 failed
  • npm run typecheck:core
  • npx prettier --check on the changed files
  • npm run check:changelog-integrity
  • npm run check:file-size
  • ✅ commit hooks: ESLint autofix, docs sync, any-budget, tracked-artifacts
  • git diff --check
  • ✅ Isolated SQLite canary: estimate-mode summary and provider breakdown reconcile after day-level grouping

Review notes

The query parameter is deliberately opt-in rather than changing the analytics default. This keeps compatibility with #5552 / #10773 while restoring analytical usefulness on the two dashboards that label cost as an estimate.

@xiaoyaner0201 xiaoyaner0201 changed the title fix(analytics): expose flat-rate estimates on Costs page fix(analytics): expose flat-rate estimates on cost dashboards Aug 25, 2026
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.

[BUG] v3.8.50 cost dashboard cannot show estimates for Claude Code flat-rate usage

1 participant