fix: bill storage cost in all modes and show it - #3247
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
WalkthroughData storage costs are deducted independently during log processing, included in organization and project metrics responses, incorporated into dashboard spend calculations, and displayed as separate storage cost metrics in the admin UI. ChangesData storage cost accounting and metrics
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
cd42cd1 to
f68523e
Compare
## Summary Marketing and docs copy claimed BYOK (bring-your-own-keys) usage is entirely free. That's still true for routing — 0% platform fee — but when an organization enables **full data retention**, storage is billed at **$0.01 per 1M tokens** from LLM Gateway credits in *all* modes, including BYOK (see theopenco#3247, which made that billing consistent). This PR adds the caveat everywhere the free-BYOK claim appears and links the [storage pricing docs](https://docs.llmgateway.io/features/data-retention#storage-pricing). ## Changes - **`packages/shared`**: add `MARKETING_STATS.dataStoragePrice` ("$0.01 per 1M tokens") next to `platformFee` as the single source of truth for surfaces that already consume `MARKETING_STATS`. - **Pricing page** (`apps/ui`): - `pricing-faq.tsx` — the "Is there a fee when I bring my own API keys?" answer now explains the optional storage charge and links "See storage pricing" to the docs section (answer is reused verbatim for FAQPage JSON-LD). - `pricing-table.tsx` — the Data Retention row gets a description ("Metadata is free; full payloads are $0.01/1M tokens") and a "See storage pricing →" link. - **Landing FAQ** (`landing/faq.tsx`) — the "How much does it cost?" BYOK bullet (both the JSON-LD string and the rendered accordion, kept in sync) now mentions the charge, with the rendered version linking the docs section. - **Comparison pages** — pricing FAQ answers on `/compare/open-router`, `/compare/portkey`, `/compare/litellm`, `/compare/vercel-ai-gateway`, `/compare/aws-bedrock`, `/compare/azure-ai-foundry`, and the `/open-source` FAQ. - **DevPass** (`apps/code/Faq.tsx`) — the pay-as-you-go answer gets the same parenthetical. - **Docs** (`learn/provider-keys.mdx`) — the "without additional gateway fees" intro now notes the optional storage charge and links `/features/data-retention#storage-pricing`. ## Deliberately unchanged - Headline one-liners, meta descriptions, hero badges, and referral copy saying BYOK has "0% / zero platform fees" — that claim remains accurate (storage is a separate, opt-in charge); the nuance lives in FAQ/detail copy where users check fees. - Comparison-table platform-fee rows ("5% or 0% (BYOK)") for the same reason. - Dated blog posts. ## Testing - `pnpm build` — 17/17 tasks pass. - `pnpm format` — clean. https://claude.ai/code/session_0196L4fULdokeKNu7stvbLWm <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated pricing FAQs and provider-key guidance to clarify that optional full data retention costs **$0.01 per 1M tokens**. * Added storage-pricing links and clearer explanations of retention charges. * **Pricing** * Displayed the data-storage price consistently across pricing, comparison, and retention sections. * Clarified that charges may apply to BYOK and managed usage when full data retention is enabled. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
f68523e to
2e01ff5
Compare
Data retention storage cost was recorded on every log but only ever deducted for api-keys mode logs with a nonzero inference cost. Credits mode (including dev/chat plan pools), wallet-backed traffic and zero-inference-cost logs (unbilled refusals) never paid it. Deduct storage for every log with a storage cost, independent of mode and inference cost. Also surface it: the admin org/project usage metrics now return and display a Storage Cost tile, and the dashboard's Total Spend headline includes storage (with the existing breakdown subtitle). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2e01ff5 to
94b9c8a
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Problem
Data retention storage cost (
log.dataStorageCost, $0.01/M total tokens when retention is on) was recorded on every log and aggregated into hourly stats, but was almost never actually billed or shown:api-keysmode logs — despite a comment claiming credits mode includes it,log.cost(=totalCostincosts.ts) never contains storage. Credits-mode orgs (including DevPass/chat plan pools), wallet-backed end-user traffic, and logs with zero inference cost (e.g. unbilled refusals, whose storage cost is intentionally preserved byzeroInferenceCosts) never paid storage at all. Example from admin: a DevPass org with retention on ran ~519M tokens/day ≈ $5.19/day of storage that was never deducted.dataStorageCostfrom the hourly stats, so the tiles summed exactly to inference cost with storage invisible.Changes
apps/worker/src/worker.ts: deduct storage cost from org credits for every log that has one, independent ofusedModeand of whether inference cost is nonzero. Inference cost handling is unchanged (credits mode deducts full cost; api-keys/BYOK pays the provider directly). Storage is never counted as premium usage.apps/api/src/routes/admin.ts: org and project metrics endpoints now aggregate and returndataStorageCost.ee/admin: new "Storage Cost" tile on org and project usage metrics; "Total Cost" subtitle clarifies it excludes storage.apps/ui: dashboard "Total Spend" (value, delta, sparkline, avg/request) now includes storage; the storage breakdown subtitle is unchanged.Notes
pnpm vitest run apps/worker/src/log-processing.spec.ts: 15/15 pass. Failures insync-models.spec.ts/stats-calculator.spec.tsare pre-existing shared-test-DB flakes unrelated to this diff.pnpm buildandpnpm formatpass.Screenshots
UI dashboard — Total Spend now includes storage, with the storage amount broken out in the subtitle:
Admin dashboard — new Storage Cost tile on the org usage metrics:
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes