Repository navigation
fix(router): cost_estimate reads the per-row platform fee (PF-8) - #118
Merged
Merged
Conversation
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.
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
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 listpricing.input/pricing.outputrates times1 + platform_fee_percent / 100. The SDK's routingcost_estimatedid not read that field.router_adapter.platform_fee_percent(row)readspricing.platform_fee_percent(both gateways), then the row's top-levelplatform_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_modefree, flat, media (per_image,per_second, ...) and Decisions (per_token, PF-5), and any row with a flat price.build_model_pricingstores it on each entry (CatalogPricing, aModelPricingwith one optional key). List rates are unchanged, so routing and ranking are unchanged.route_with_catalogcomputes a per-token model's estimate as list cost x (1 + fee/100) viatoken_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_costmultiplies every estimate by a hardcodedSERVER_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_USDand leaves it there; this PR keeps that.max_cost_per_call/max_session_costare enforced against the gateway's signed 402 quote, which already includes the fee, so they need no change. The estimate is metadata only.Tests
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 includesplatform_fee_percent: 0.0.test_solana_poll_ownership.py(5 s video/image poll timeouts) and fail the same way on unmodifiedorigin/mainon this machine.ruff check blockrun_llm/ tests/: clean.black --check: clean.mypy blockrun_llm/: 249 errors, identical toorigin/main; none inrouter_adapter.py.No version bump, no publish.
🤖 Generated with Claude Code