Skip to content

feat(pricing): include the chat platform fee in cost estimates (PF-8) - #250

Merged
VickyXAI merged 1 commit into
mainfrom
feat/platform-fee-estimate
Nov 19, 2026
Merged

VickyXAI merged 1 commit into
mainfrom
feat/platform-fee-estimate

Conversation

@VickyXAI

Copy link
Copy Markdown
Contributor

What

The gateways now charge a platform fee on per-token paid chat (BlockRunAI/blockrun specs/2026-11-16-chat-platform-fee.md PF-1..PF-9) and publish it on /v1/models as platform_fee_percent. Sol puts it inside pricing; 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 only pricing.input / pricing.output, so they came in below the real charge by the fee.

Changes

  • src/pricing.ts
    • platformFeePercent(row) reads pricing.platform_fee_percent first, then the row's top-level platform_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 whose billing_mode is not paid, so free, flat, media and Decisions rows never get the fee.
    • platformFeeFactor and tokenCostUsd are the one place that applies (1 + fee/100).
    • updatePrices copies the fee from each live catalog row into MODEL_PRICING[id].platformFeePercent. The @blockrun/model-catalog projection keeps only input/output, so the fee has to come from the full row. The list rates themselves stay unchanged.
    • estimateCost uses tokenCostUsd for per-token models. The per-call path (perCall) is unchanged.
  • Opus "saved vs Opus" baselines (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

  • Transaction fee. estimateCost has 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 estimator estimateCostUsd already adds the transaction fee and is unchanged; it returns 0 for paid rows.
  • Static and bundled prices. LEGACY_PRICING and the bundled @blockrun/model-catalog snapshot 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.
  • Router. SHARED_MODEL_PRICING and the router's computeSavings and selector use 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_PRICING is also built once at module load from the bundled state, which has no fee. In addition, router-core's own calculateModelCost already applies its own server margin, so adding the fee host-side would count it twice.

Tests

  • New tests in test/model-catalog.local.mjs:
    • Helper: nested field, top-level fallback, nested preferred, malformed or absent → 0, and free/flat/media ignored.
    • Live-refresh 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 --noEmit is clean, and node scripts/sync-brand-numbers.mjs --check is clean.
  • The helper was checked against today's live Base and Sol /v1/models. Both gave 88 paid rows at 5 and every other row at 0.

🤖 Generated with Claude Code

…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.
@VickyXAI
VickyXAI merged commit e66f20e into main Nov 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant