Skip to content

feat(cost): price custom models and split session spend by category - #726

Merged
huichen merged 1 commit into
mainfrom
feat/cost-display
Sep 19, 2026
Merged

huichen merged 1 commit into
mainfrom
feat/cost-display

Conversation

@huichen

@huichen huichen commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

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.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 a matching built-in catalog price; a partially filled price writes all four fields explicitly. list_providers reports the rates back so the edit form round-trips them.
  • get_state.usage gained costInputCny / costOutputCny / costCacheReadCny / costCacheWriteCny, 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 are never double-counted.
  • New ProviderModel (fields 7-10) and SessionUsage (fields 6-9) proto fields; the generated file was regenerated from future.proto.

Clients

  • Desktop: the thread header shows the running amount and opens a token/amount breakdown; the custom-provider form gained the four price fields and rejects negative / non-finite rates before anything is sent.
  • Mobile: the amount sits in the chat top bar and opens a sheet which also owns the rename entry, so the bar stays a single row (a low-frequency action moves next to the title it edits).
  • An unpriced model reports zeros, so rows show tokens only; the total is still whatever was actually billed. Nothing fabricates a ¥0 breakdown, and the rows are labelled as an estimate when the provider bills itself.

Checks

  • cargo fmt --check / cargo clippy --all-targets -D warnings / cargo test for future-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).
  • Desktop: tsc --noEmit, eslint, vitest run (1183 passed).
  • Mobile: tsc --noEmit, eslint, jest (1698 passed; the single MarkdownText.test.ts failure is the known worktree node_modules-symlink artifact — @future-os/markdown resolves to the main worktree's copy, so the jest.spyOn target differs; it fails the same way without this branch).

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.
@huichen
huichen enabled auto-merge (squash) September 19, 2026 11:55
@huichen
huichen merged commit 913b745 into main Sep 19, 2026
22 of 24 checks passed
@huichen
huichen deleted the feat/cost-display branch September 19, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant