Repository navigation
Price sheets in config.yaml, a daily default table, and a price source on every request - #30
Merged
Merged
Conversation
…d a price source on every request
Prices now come in two layers, and every consumer reads one live price book.
- The default price table is the public dataset: the embedded snapshot, or
the copy the control plane refreshes once a day (`pricing.auto_update`,
on unless set to false) and saves as model_prices.json beside
config.yaml. Whichever is newer prices requests. POST /pricing/refresh
refreshes on demand, and PUT /pricing/auto_update switches the schedule.
- Price sheets live in config.yaml under `pricing.sheets`: a multiplier
over the default table, plus per-model overrides with every field
written out. Nothing is inferred when pricing, so a refreshed default
table never moves an override. An upstream picks a sheet with
`pricing:`, and naming a sheet that does not exist is a config error.
/pricing/sheets creates, renames (upstreams follow in the same version)
and deletes (refused while an upstream uses it).
- POST /pricing/query resolves prices against the default table, a saved
sheet or an unsaved draft, and returns where each price came from, so
the UI never re-implements the order.
- The recorder, the speed-test and replay quotes, cheapest routing and the
dry run all read the gateway's price book. The recorder used to keep its
own copy from startup: edited prices needed a restart, and per-upstream
prices never reached the ledger.
- Each request stores where its price came from: the default table and
its date, a sheet's multiplier, or a sheet's override (schema 11).
- The unpriced-request count on /pricing is grouped by upstream and model,
and its total no longer stops at the first 20 models.
Removed: pricing.yaml with its per-model and per-provider overrides,
PUT /pricing, and the three-step /pricing/update/{offer,fetch,apply}.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for the PR. One thing before review: this targets
No need to close and reopen: click Edit next to the PR title and change the base branch to See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract. |
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.
Why
Pricing had one table and a side file, and the pieces disagreed:
pricing.yamlonly had per-model and per-provider overrides, so a discount meant copying rows, and nothing tied an upstream to a set of prices.cheapestrouting sorted by one price while the cost column recorded another, and an edited price needed a restart.What
Two layers (
tw-pricing)config.yamlunderpricing.sheets: a multiplier over the default table, plus per-model overrides in dollars per million tokens.pricing:. Without one, the default table applies. Naming a sheet that does not exist is a config error, rather than silently charging default prices.PriceBookbehindArcSwapis shared by forwarding (cheapest), the recorder, the speed-test and replay quotes, and the dry run. A config reload swaps the sheets and a refresh swaps the table, both throughrcu, so neither overwrites the other.Runtime refresh (
tw-control/src/pricing.rs)pricing.auto_update: false. The first check is a minute after start.model_prices.jsonbesideconfig.yamlbefore the book is swapped.Endpoints
GET /pricingreturns the table's date, source and size, whether auto-update is on, the last attempt and its error, and unpriced requests from the last 7 days grouped by upstream and model.POST /pricing/refreshrefreshes now. It runs whether or not auto-update is on.PUT /pricing/auto_updatewritesauto_update: false, or removes the key when switched back on.POST /pricing/queryprices models against the default table, a saved sheet, or an unsaved draft, and returns each price's source and context window. With no models given, it searches by name, and plain names come before platform-prefixed keys. The UI never re-implements the order.POST /pricing/sheets,PUTandDELETE /pricing/sheets/{name}work like the upstream resources:pricing:section behind.price_sheets(multiplier, override count, users) andProviderView.pricing.ProviderInput.pricingsets it.Recording
HistoryRow.price_sourceexposes it.Removed
pricing.yamland its overrides.PUT /pricing./pricing/update/{offer,fetch,apply}and their types.blake3dependency intw-control.Tests
tw-pricing, 48 tests:tw-store:tw-control/tests/pricing.rs, 10 tests against the real config file:fmt,clippy -D warningsandcargo test --workspace(1,234 tests) pass.scripts/smoke.sh: 48 passed, 0 failed, 1 over target and not a regression (memory 34 MB against a 30 MB target).🤖 Generated with Claude Code