mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4747] [Engine] serve: price a prompt the way an API does — a cache write and a cache read #5160
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5160
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4747
Author: @au70ma70n
Created: 10/30/2026
Status: 🔄 Open
Base:
main← Head:engine-cache-rate-pricing📝 Commits (4)
145e349[GUI] settings: let a long help line wrap instead of squeezing every field419a478[Engine] serve: keep the Monitor's token counts between starts0b7d7d9[Engine] serve: print what the counted tokens would have cost at your own pricesc26248b[Engine] serve: price a prompt the way an API does — a cache write and a cache read📊 Changes
7 files changed (+537 additions, -6 deletions)
View changed files
📝
docs/DETAILS.md(+18 -1)📝
serve/runconfig.py(+10 -0)📝
serve/server.py(+183 -1)➕
serve/test_totals.py(+282 -0)📝
serve/web/app.css(+7 -2)📝
serve/web/app.js(+36 -2)📝
serve/web/index.html(+1 -0)📄 Description
Draft — the costing story wants scope agreement first: #4742. It lands after #4746 (it splits that PR's plain prompt price into a cache write and a cache read); merge order is #4743 → #4745 → #4746 → this one, and until the branch before it merges this pull request's diff also shows those commits and shrinks on its own as they merge.
Branch
engine-cache-rate-pricing, basemain.Problem and result
To an API a prompt is not one price. The tokens the conversation cache already held are re-read far below the price of a new token, and the tokens that had to be added to it are a cache write. Before this PR the whole prompt was priced at the plain input price, so a long cached agent session looked far dearer than the same work at an API. After:
cost_cache_write_per_millionandcost_cache_hit_per_millionin the run config and the Settings view, with--cost-cache-writeand--cost-cache-hitfor one start. Either one left unset takescost_input_per_million, so a model priced without prompt caching needs only #4746's two numbers and is priced exactly as before; an explicit0is a price of its own (some APIs charge nothing for a re-read), not an unset one. The server prints the rates it is costing at when it starts, so a wrong price shows at once. The page names the parts apart — "about $4.08 at $6.25 per million written to the cache, $0.50 per million re-read, $25 per million out" — and only when they are priced apart from plain input.Related discussion
#4742 — the scope thread for the costing story (this pull request, #4745 which keeps the counts, and #4746 which prices them plainly).
Otherwise none found: sampled searches on
cost OR price OR totals(342 pull requests, 753 issues — first pages only) turned up nothing on cache write or cache read pricing; nothing claims this work, though the search was not exhaustive.Approach
totals_costsplits the prompt atreused:given - reusedat the write rate,reusedat the read rate, the reply at the output price, all over 1,000,000 — andreusedis clamped togiven, so a damaged count cannot invent a credit.totals_with_costechoes the rate each kind of token is actually paid at, which is the plain input rate when a cache rate was never set, so a page can name the rate it shows rather than guess one. The same counts as #4746's example — 2,000,000 given, 1,900,000 of them held — priced at $6.25 written, $0.50 read and $25 out come to 0.1 × $6.25 + 1.9 × $0.50 + 0.1 × $25 = $4.075, against #4746's $12.50 for the same work.Validation
Passed: the 9 tests that are this PR's:
Cost.test_a_read_the_cache_held_is_paid_for_as_input,Cost.test_a_re_read_is_paid_at_the_cache_price,Cost.test_an_added_token_is_paid_at_the_write_price,Cost.test_the_prices_of_a_real_price_list_on_a_day_of_agent_turns,Cost.test_a_free_cache_read_is_a_price_and_not_a_missing_one,Cost.test_the_page_is_told_the_rate_each_kind_of_token_is_paid_at, andPriceSettings.test_the_cache_prices_are_editable_from_the_page_too,test_a_cache_price_is_dollars_and_cents,test_a_cache_price_of_nothing_is_a_price_of_nothing. Environment as in #4745's Validation (Windows 11 NT 10.0.26200, Python 3.10.11, no GPU and no downloads, at870aedd9+ these changes).Failed: none observed.
Not run: these figures against a real API bill (the arithmetic is tested; the price list is the user's own);
npm testand the Terminal suite, as in #4745's and #4746's notes.Limits
One flat rate per part, so a tiered price list (one price to 200k, another above) still has to be a single number; whether a cache write is the 5-minute or the 1-hour rate is the user's choice, not a server decision, and the shipped default leaves both rates unset.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.