Repository navigation
feat(catalog): add optional tiered-price and cache-write price fields - #416
Merged
Merged
Conversation
Models can now express per-request input-length tiers ([[models.tiers]]) and a cache-write price (cache_write_input_per_m). Both are optional and default off, so a catalogue without them is unchanged; validation rejects non-increasing from_tokens, zero/negative tier boundaries and negative prices. Wiring these into settle is a follow-up step. Ref: rant 2026-10-16T14:08:14 (tiered input pricing)
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.
Summary
Adds the expression capability and validation for two price features the catalogue
currently cannot express (rant
2026-10-16T14:08:14, 【计价】tiered input price +cache-write price):
Per-request input-length tiers — an optional
[[models.tiers]]array:from_tokensis the inclusive lower bound of the tier; the model's owninput_per_m/cache_hit_input_per_m/output_per_mare the first tier.Cache-write price — an optional
cache_write_input_per_mfield, defaulting to0("cache writes are free", i.e. today's behaviour).Both fields are
#[serde(default)], so every existing catalogue row parses exactly asbefore and pricing is byte-for-byte unchanged —
settleis deliberately not touchedin this step.
Config::validategains the rules that the data itself cannot be trusted to satisfy:tier
from_tokensmust be> 0and strictly increasing, and no tier price (orcache_write_input_per_m) may be negative. Tier data goes straight into real money, soa malformed catalogue is rejected at load time instead of mis-pricing silently.
Scope — this is step 1 of 2
The rant asks for two steps; this PR is the first:
path reads them yet.
src/db.rs::seed_modelsinto themodelstable and select the tier by the request'sinput-token count in
settle, and per-tier boundary tests for each vendor.The tests below pin the backward-compatibility half of the rant's acceptance criteria
(no-tier rows price identically — settle and its expectations are untouched, suite
unchanged counts).
Related Issue
Rant
2026-10-16T14:08:14(【计价】按输入长度分档的价格、以及缓存写入价,都没有字段).Tests
cargo test: 571 passed / 0 failed (564 before; the 7new tests are below)
parse_model_tier_from_toml— a tier parses field-by-field;cache_hit_input_per_mdefaults to 0model_defaults_to_no_tiers_and_zero_cache_write— every example row defaults to empty tiers / zero cache-write pricevalidate_accepts_strictly_increasing_tiers— positive controlvalidate_rejects_non_increasing_tier_boundary— duplicate and decreasing boundariesvalidate_rejects_zero_tier_boundaryvalidate_rejects_negative_tier_pricevalidate_rejects_negative_cache_write_pricecargo fmtcleancargo clippy --all-targets -- -D warningscleanRUSTFLAGS="-D warnings" cargo build) — the only witnessthat the new fields are read by production code, not just tests