Skip to content

fix(router): cost_estimate reads the per-row platform fee (PF-8) - #118

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

Spec PF-8 (BlockRunAI/blockrun specs/2026-11-16-chat-platform-fee.md): blockrun.ai and sol.blockrun.ai charge per-token paid chat its list pricing.input / pricing.output rates times 1 + platform_fee_percent / 100. The SDK's routing cost_estimate did not read that field.

  • router_adapter.platform_fee_percent(row) reads pricing.platform_fee_percent (both gateways), then the row's top-level platform_fee_percent (blockrun.ai), and returns 0 when neither is a finite, non-negative number. Older gateways and enterprise (PF-9) send none. It also returns 0 for any row that is not per-token paid chat: billing_mode free, flat, media (per_image, per_second, ...) and Decisions (per_token, PF-5), and any row with a flat price.
  • build_model_pricing stores it on each entry (CatalogPricing, a ModelPricing with one optional key). List rates are unchanged, so routing and ranking are unchanged.
  • route_with_catalog computes a per-token model's estimate as list cost x (1 + fee/100) via token_cost_usd, then applies the existing payment floor. Flat and unpriced entries keep Router Core's estimate.

Behaviour change to note

Router Core's calculate_model_cost multiplies every estimate by a hardcoded SERVER_MARGIN_PERCENT (the media margin). The adapter now replaces that for per-token entries with the per-row fee. Against blockrun.ai and sol.blockrun.ai the number is the same today; against a gateway that publishes no fee (enterprise, older gateways) or a hand-built price map without the key, the estimate is now the list cost rather than list + that margin. router_core/ is an upstream port and is not edited.

Transaction fee

The SDK does not add the flat per-call transaction fee to the estimate. It floors paid estimates at BASE_MINIMUM_PAYMENT_USD / SOLANA_MINIMUM_PAYMENT_USD and leaves it there; this PR keeps that. max_cost_per_call / max_session_cost are enforced against the gateway's signed 402 quote, which already includes the fee, so they need no change. The estimate is metadata only.

Tests

  • New tests/unit/test_platform_fee_estimate.py (27 tests): nested field, top-level fallback, nested preferred, absent -> 0, unusable values -> 0 (and still fall back to top level), free / flat / media / Decisions -> 0, pricing-map entries, estimate with nested and top-level fee, absent fee at list price, fee does not change model selection, free stays 0, floor still applies.
  • test_routing_parity.py: the pricing-map entry assertion includes platform_fee_percent: 0.0.
  • Full suite: 1636 passed, 15 skipped, 3 failed. The failures are in test_solana_poll_ownership.py (5 s video/image poll timeouts) and fail the same way on unmodified origin/main on this machine.
  • ruff check blockrun_llm/ tests/: clean. black --check: clean. mypy blockrun_llm/: 249 errors, identical to origin/main; none in router_adapter.py.

No version bump, no publish.

🤖 Generated with Claude Code

Per-token paid chat is charged list rates x (1 + platform_fee_percent/100).
build_model_pricing now carries the fee from pricing.platform_fee_percent,
falling back to the row's top-level field, 0 when absent or unusable, and 0
for free, flat, media and Decisions rows. route_with_catalog uses it for the
per-token estimate instead of Router Core's hardcoded server margin; flat and
unpriced entries keep Router Core's estimate.
@VickyXAI
VickyXAI merged commit fcfa6e0 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