docs(usage): add cost tracking guide#442
Conversation
Document how GoModel estimates request costs, where pricing is resolved from, how to override pricing, the dashboard Estimated vs Saved Cost cards, and the recalculate-costs action. A warning up front states the figures are estimates, not a billing record. The override and recalc sections include the surprising behaviours surfaced in issue #435: cached-token discounts depend on catalog cached_input_per_mtok, and recalculation clears (rather than preserves) the cost of rows whose model no longer resolves to pricing. Two screenshot placeholders are left in the override section for the Models page and the pricing override editor. Also add regression tests that pin the behaviour the guide describes: - dashboard cost aggregation end to end (live spend vs cache savings, cached discounts for nested and DeepSeek top-level cache fields). - recalculation correcting stale pre-fix cached costs and nulling rows that lose pricing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a cost-tracking documentation page and nav entry, plus two SQLite-backed Go tests covering dashboard cost aggregation and stored-cost recalculation behavior. ChangesCost Tracking Docs and Tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Confidence Score: 5/5The documentation and regression-test additions appear safe to merge. The changed files are limited to a new guide, docs navigation, and targeted tests for the documented cost-tracking behavior, with no review comments requiring code changes.
What T-Rex did
Reviews (1): Last reviewed commit: "docs(usage): add cost tracking guide" | Re-trigger Greptile |
Replace the placeholder slots in the cost tracking guide with screenshots of the Pricing override editor on the Models page. Images downscaled to stay under the repo large-file limit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/usage/recalculate_pricing_issue435_test.go`:
- Around line 20-24: The SQLite test setup in the db initialization block should
be pinned to a single connection so the in-memory database is shared across all
operations. Update the test around sql.Open in RecalculatePricing-related setup
to call db.SetMaxOpenConns(1) (or use a shared-cache in-memory DSN) before
running WriteBatch, RecalculatePricing, and the validation queries, so they all
use the same connection and see the same tables and rows.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1e1cd918-b38b-43b2-b30c-11e3d1d271ef
⛔ Files ignored due to path filters (2)
docs/features/pricing-override-editor.pngis excluded by!**/*.pngdocs/features/pricing-override-models.pngis excluded by!**/*.png
📒 Files selected for processing (4)
docs/docs.jsondocs/features/cost-tracking.mdxinternal/usage/dashboard_cost_validation_test.gointernal/usage/recalculate_pricing_issue435_test.go
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the models screenshot with the clean Registered Models list (no dialog) showing the per-row pricing override action, and update its caption and alt text. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A bare ":memory:" DSN gives each pooled connection its own private database, so database/sql can route WriteBatch, RecalculatePricing, and the validation queries to different empty databases. Pin the pool to one connection so all operations share the same in-memory DB. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Adds a Cost tracking docs page (
docs/features/cost-tracking.mdx, wired intodocs.jsonunder Features) and regression tests that pin the behaviour it describes. Follow-up to #439 / issue #435, which exposed that the cost model is non-obvious and undocumented.The page covers
<Warning>up front: figures come from catalog pricing and provider-reported token counts and can differ from a provider's bill (promotions, rounding, cache rules, currency, plan discounts). Provider dashboard is the source of truth.cost_sourceper row.config.yaml→ catalog.---means unknown, not$0.USAGE_PRICING_RECALCULATION_ENABLED=true), typed confirmation, scoped to the current filters. A<Warning>documents that recalculation clears the cost of rows whose model no longer resolves to pricing rather than preserving it.Regression tests (validate what the guide documents)
internal/usage/dashboard_cost_validation_test.go— full chain (extractor → SQLite store → reader): Estimated Cost excludes cache hits, per-model totals, Saved Cost from the cache overview; cached discounts apply for both nested (prompt_cached_tokens) and DeepSeek top-level (prompt_cache_hit_tokens) reporting.internal/usage/recalculate_pricing_issue435_test.go— recalc corrects a stale pre-fix cached cost (and clears its caveat) and nulls a row whose model lost pricing, counting it asWithoutPricing.Screenshots — action needed
I could not capture the two override screenshots (the Chrome extension wasn't connected in this session), so the page has two clearly-marked placeholder slots in the Override pricing section, each with a
TODOcomment containing the ready-to-paste<img>snippet. To fill them: run the dashboard, open/admin/dashboard/models, capture the Models row action and the Pricing override editor, save asdocs/features/pricing-override-models.pnganddocs/features/pricing-override-editor.png, and replace the placeholder<div>s.Checks
Pre-commit passed:
mint validate,make test-race,make lint,go mod tidy.🤖 Generated with Claude Code
Summary by CodeRabbit
Documentation
Bug Fixes