Repository navigation
feat(cost): price custom models and split session spend by category - #726
Merged
Merged
Conversation
A session's spend was one opaque number: the amount the provider reported (`credit_cost`, only the Future platform) or the registry's estimate, with no way to see where it came from, and custom models could not be priced at all. Agent: - `models.json` model entries accept a `cost` object (per-1M-token input/output/cache_read/cache_write). It is omitted entirely when every rate is 0, so a model keeps inheriting the built-in catalog price for its id; a partially filled price writes all four fields. `list_providers` reports the rates back so the edit form round-trips them. - `get_state` usage carries `cost_input_cny` / `cost_output_cny` / `cost_cache_read_cny` / `cost_cache_write_cny`, derived from the resolved model's rates with the same rule as `Cost::estimate`: the non-cached input remainder is billed at the input rate, so cached tokens never double-count. Clients: - Desktop: the thread header shows the running amount and opens a token/amount breakdown; the custom-provider form gained the four price fields (rejecting negative / non-finite rates before anything is sent). - Mobile: the amount sits in the chat top bar and opens a sheet that also owns the rename entry, keeping the bar to one row. - The per-category figures are 0 for an unpriced model and the rows then show tokens only — the total is still whatever was actually billed, so a client never fabricates a ¥0 breakdown, and the rows are labelled as an estimate for a provider that bills itself.
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
A session's spend was one opaque number: either the provider's own billing (
credit_cost, only the Future platform) or the registry's estimate — with no way to see where it came from. Custom models could not be priced at all, so every third-party provider priced at zero.What changed
Agent (wire + pricing)
models.jsonmodel entries accept acostobject (per-1M-tokeninput/output/cache_read/cache_write). It is omitted entirely when every rate is 0, so a model keeps inheriting a matching built-in catalog price; a partially filled price writes all four fields explicitly.list_providersreports the rates back so the edit form round-trips them.get_state.usagegainedcostInputCny/costOutputCny/costCacheReadCny/costCacheWriteCny, derived from the resolved model's rates with the same rule asCost::estimate: the non-cached input remainder is billed at the input rate, so cached tokens are never double-counted.ProviderModel(fields 7-10) andSessionUsage(fields 6-9) proto fields; the generated file was regenerated fromfuture.proto.Clients
Checks
cargo fmt --check/cargo clippy --all-targets -D warnings/cargo testforfuture-agent(1788 passed),future-rpc,future-tui,future-cli(733 passed).desktop/src-tauri:cargo fmt --check,cargo clippy --all-targets -D warnings,cargo test agent_providers(51 passed).tsc --noEmit,eslint,vitest run(1183 passed).tsc --noEmit,eslint,jest(1698 passed; the singleMarkdownText.test.tsfailure is the known worktreenode_modules-symlink artifact —@future-os/markdownresolves to the main worktree's copy, so thejest.spyOntarget differs; it fails the same way without this branch).