Repository navigation
feat(billing): show where AI credits go on the billing page - #2529
Conversation
A new AI credits section under Usage: this cycle's spend, the split by feature and by model, and for code review the cost by repository, the most expensive pull requests and the re-reviews later pushes caused. Each PR review now records what the provider billed for it (pr_reviews. cost_microusd), so code review spend is read from Postgres per repository and pull request; the feature and model splits come from Autumn's events grouped by source and by model. Reviews from before the column count without credits and the page says how many.
…s the bill Review feedback: the cost was written only when a submission completed the row, but every turn is billed. It is now added to the review's row when the turn ends, beside metering, so superseded, failed and re-run reviews carry what they cost; turns on the org's own key record nothing, as Maple bills nothing for them. The breakdown counts every review that ran (a superseded one included), counts as unpriced only a completed review with no cost, and covers every org a billing org pays for. By model shows spend with no model as Unattributed, the code review read gives up after 5 seconds, and pull request links say where they go.
…t never started is not counted
Second review pass: an own-key review recorded no cost, so it read as unpriced
("ran before costs were kept"); it now records 0. A review that failed before
its turn began ran nothing, so it no longer counts as a review or makes the
real one a re-review.
|
Caution Review failedThe pull request is closed.
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. |
This comment has been minimized.
This comment has been minimized.
🍁 Maple PR previewNote Preview resources were removed when this pull request closed. Final commit |
The breakdown now lives at /settings/billing/ai-credits (Settings › Billing › AI credits) instead of inline on the billing page; the AI credits usage row links to it with "Details". The response carries the cycle bounds the page dates its spend from, the breakdown view moved to page/kit/billing, and /lab/ai-credits shows the page's states.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
… lint and page sample fixes Maple review: a review superseded or failed mid-run before costs were kept was counted but not reported as unpriced. Every turn now records its cost, so any review that ran without one (and is not still running) predates the column. Also size the billing row's Details link through typography rather than a className on the kit link (lint:foldkit), and give the AI credits page a sample URL in the lazy page-slot test.
This comment has been minimized.
This comment has been minimized.
…eview
The "Most spent on" tile shows the credits as its figure and the feature below
it, so a long feature name no longer runs past the tile at phone width; the
breadcrumb names the tab as the settings nav does ("Billing & usage"); and the
lab's retry answers with its fixture instead of dropping the page's read.
This comment has been minimized.
This comment has been minimized.
… spend when the model split fails Maple review: a member org's page totalled the whole bill but its code review breakdown covered only itself; it now resolves the paying org and reads it with every org it pays for. And a failed by-model aggregate failed the whole read; it now drops only the model table.
This comment has been minimized.
This comment has been minimized.
Maple review🟢 Confidence 10/10 · safe to merge. The tenant-scoped spend query and the additive Adds an AI credits page at
Before merge
Fixed since the last review
Production impactOpen errors in the changed files (2)
After this merges, Maple checks whether they stop.
|
|
Merged with 1 step from "Before merge" still open. If it is done, tick it on the review comment; if not, now is the time.
|
Maple: after this shipped✅ Shipped clean. Nothing this change touches got worse in the hour after it deployed. Deployed to Errors in the changed files:
Maple looks once, an hour after the first deploy that carries the merge. |
Stacked on #2526.
What
The billing page shows one line for AI credits today ("Code review $3.62"). This adds an AI credits page at
/settings/billing/ai-credits(Settings › Billing › AI credits), linked from that row with Details, that answers where the credits went this cycle:How
pr_reviews.cost_microusd. When a review turn ends, beside metering, the turn's reported provider cost (from fix(billing): bill AI credits at the provider's reported cost #2526) is added to the review's row (PrReviewService.addCost,coalesce(cost, 0) + x). Superseded, failed and re-run reviews carry what they cost. Turns on the org's own OpenRouter key record nothing, since Maple bills nothing for them.PrReviewAnalyticsService.spendreads the cycle's reviews in Postgres: totals, by repository, top pull requests and re-review cost. It counts every review that ran, superseded ones included, and covers every org a billing org pays for.GET /internal/billing/ai-credit-usagegains the cycle bounds,byModel(Autumn events grouped byproperties.model, checked against production data) andcodeReview. The code review read is optional detail: a failure or a read slower than 5 seconds drops it, never the spend.page/settings/ai-credits, its breakdown inpage/kit/billing/ai-credits.ts, built from kit pieces. The billing page's AI credits row gains the Details link;formatCreditsand the surface labels moved to the billing kit. The colour dot that repeated across billing views became aroundoption on the kit'sswatch.Reviews from before this ships count without credits, and the page says how many.
Screenshots
From
/lab/ai-credits(statescode-review,chat,empty,loading,error) and/lab/billing-orgs?state=ai-credits.Billing page: the AI credits row links to the page
The page
Verification
addCost: adds across a failed turn and ignores another org.recordReviewCost: skipped on the org's own key, outside a review, and when no call was priced.oxlint -c .oxlintrc.effect.json;ui:patterns:check;ui:index:check; the kit baseline (unchanged);ios:openapi:check.Not covered
pr-reply) are billed as code review but have nopr_reviewsrow, so they show under By feature only.