Repository navigation
feat(pricing): include the chat platform fee in cost estimates (PF-8) - #250
Merged
Merged
Conversation
…tes (PF-8) Per-token chat estimates now multiply list cost by (1 + platform_fee_percent/100), read from a live /v1/models row: pricing.platform_fee_percent first, then the row's top-level field, 0 when absent or malformed (older gateways, enterprise PF-9). Only billing_mode 'paid' rows carry it; free, flat and media rows are final prices. The Opus savings baselines use the same basis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The gateways now charge a platform fee on per-token paid chat (BlockRunAI/blockrun
specs/2026-11-16-chat-platform-fee.mdPF-1..PF-9) and publish it on/v1/modelsasplatform_fee_percent. Sol puts it insidepricing; Base puts it there and at the top of the row (blockrun#1142). PF-8 says Franklin's cost estimates must read it. Before this change they read onlypricing.input/pricing.output, so they came in below the real charge by the fee.Changes
src/pricing.tsplatformFeePercent(row)readspricing.platform_fee_percentfirst, then the row's top-levelplatform_fee_percent. It returns 0 when the field is absent or is not a finite non-negative number, because older gateways and enterprise (PF-9) don't send it. It returns 0 for any row whosebilling_modeis notpaid, so free, flat, media and Decisions rows never get the fee.platformFeeFactorandtokenCostUsdare the one place that applies(1 + fee/100).updatePricescopies the fee from each live catalog row intoMODEL_PRICING[id].platformFeePercent. The@blockrun/model-catalogprojection keeps only input/output, so the fee has to come from the full row. The list rates themselves stay unchanged.estimateCostusestokenCostUsdfor per-token models. The per-call path (perCall) is unchanged.agent/loop.ts,commands/start.ts,stats/tracker.ts,stats/insights.ts) now include Opus's fee. They are compared against real x402 charges, which include the fee, so both sides now use the same basis.src/gateway-models.ts: two comments still said chat carries no margin. They now point at the per-row field. No code changed in this file.Not changed, on purpose
estimateCosthas never added the flat per-transaction fee, and it still doesn't. It is only a fallback for when no x402 charge was observed (free, cached, API-key mode), and the real charge is preferred over it. The media estimatorestimateCostUsdalready adds the transaction fee and is unchanged; it returns 0 forpaidrows.LEGACY_PRICINGand the bundled@blockrun/model-catalogsnapshot have no fee field. An id priced only from them (offline, or a hidden id that the live catalog no longer lists) still estimates at 0% fee. Nothing infers the fee from elsewhere.SHARED_MODEL_PRICINGand the router'scomputeSavingsandselectoruse relative cost only: savings as a ratio against the Opus baseline, and min-max cost scores. A fee applied evenly to paid rows doesn't change either.SHARED_MODEL_PRICINGis also built once at module load from the bundled state, which has no fee. In addition, router-core's owncalculateModelCostalready applies its own server margin, so adding the fee host-side would count it twice.Tests
test/model-catalog.local.mjs:estimateCost: covers the same cases, plus "list rate not rewritten", the Opus baseline fee, and dropping the fee when a later catalog stops sending it.npx tsc --noEmitis clean, andnode scripts/sync-brand-numbers.mjs --checkis clean./v1/models. Both gave 88 paid rows at 5 and every other row at 0.🤖 Generated with Claude Code