Repository navigation
feat: finish model cost accounting - #46
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedNext included review available in 12 minutes. View limit detailsLimit details: You’ve used the included review currently available. Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Free Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (18)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting https://app.coderabbit.ai/settings/billing. Comment |
|
@coderabbitai review |
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Two moderate findings block approval, and the audit evidence path needs a portability fix.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Completes OpenRouter model-cost accounting, separates source-import volume from AI costs, and refreshes pricing evidence.
Changes:
- Tracks terminal usage and marks incomplete streams non-billable.
- Adds required audit inserts and paginated, import-aware admin aggregation.
- Updates pricing captures, tests, tooling, and documentation.
| File | Reviewed changes / findings |
|---|---|
supabase/functions/ai/index.ts |
Requires audit-column inserts without fallback. |
supabase/functions/ai-stream/index.ts |
Tracks terminal usage and incomplete streams. Moderate finding (3 votes): exception paths after a finish reason can retain provider cost. |
supabase/functions/ai-stream/index_test.ts |
Tests stream accounting scenarios. |
supabase/functions/ai-stream/handler_test.ts |
Verifies terminal usage requests. |
supabase/functions/admin/index.ts |
Adds paginated, import-aware aggregation. Moderate finding (1 vote): unknown-cost counts can be mislabeled as missing token data. |
supabase/functions/_shared/model-pricing.ts |
Updates pricing snapshot metadata. |
supabase/functions/_shared/cost.ts |
Adds incomplete-usage marking. |
supabase/functions/_shared/cost.test.ts |
Tests incomplete cost handling. |
supabase/functions/_shared/admin-cost.ts |
Adds cost classification and pagination helpers. |
supabase/functions/_shared/admin-cost.test.ts |
Tests admin accounting rules. |
package.json |
Adds the pinned tsx dependency. |
package-lock.json |
Locks dependency changes. |
docs/testing.md |
Documents stream-accounting tests. |
docs/pricing-snapshots/openai.md |
Refreshes OpenAI pricing evidence. |
docs/pricing-snapshots/anthropic.md |
Refreshes Anthropic pricing evidence. |
docs/pricing-snapshots/metadata.json |
Updates pricing hashes and metadata. |
.audit/model-cost-accounting.tsv |
Records execution and review evidence. Nit (1 vote): browser evidence uses a host-specific local path. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|

Problem and result
Incomplete streams could retain a lower-bound OpenRouter charge, schema drift could be hidden by a fallback insert, and URL imports appeared as unknown AI cost. This change makes incomplete or cancelled provider work non-billable while retaining observed usage, removes the audit-column downgrade path after verified schema parity, and keeps importer volume separate from AI cost.
The plan predated PR #43, so the implementation was rebased onto the current OpenRouter-only handlers instead of restoring removed direct-provider routes.
Active app accounting never looks up a static provider rate: every allowlisted model request runs through OpenRouter, and the stored USD charge is OpenRouter's per-response
usage.cost. The refreshed provider snapshots remain legacy audit evidence only.Changes
tsx@4.19.2; all 11 normalized rates still match, andgemini-3.1-flash-lite-previewremains unknown.audit/model-cost-accounting.tsvVerification
v22.23.2, npm12.0.2, Deno2.9.6Browser proof
The fixture contains seven requests: six OpenRouter calls and one source import. The import remains visible as Source Import volume, while cost-by-feature and cost-by-model contain only AI work. The recording covers desktop and Pixel 7 layouts.
f963842b-6d26-4bc1-9475-89e89233d3e6-e72a6d26-a7ed-4155-b759-badfb4c330dd-mp4.mp4
Database and staging
brifeyypjauyusmkptkxand productionuziwdtkzofptihahfoooboth have migration20260822000000and all seven audit columnsaiv18,ai-streamv19, andadminv13$0.00015275,openrouter-response-usage,openrouter-usage-v1, and raw usageorigin/main@99c2b53Adam will perform the final merge. Current-head CI and staging evidence are clear; CodeRabbit was rate-limited, and Adam waived the remaining review wait.