feat: populate UsageUpdate.cost with estimated session cost#216
Open
simonrosenberg wants to merge 1 commit intozed-industries:mainfrom
Open
feat: populate UsageUpdate.cost with estimated session cost#216simonrosenberg wants to merge 1 commit intozed-industries:mainfrom
simonrosenberg wants to merge 1 commit intozed-industries:mainfrom
Conversation
Derive cumulative session cost from per-turn token counts and a model pricing table, so ACP clients can display meaningful cost instead of $0.00 or null. - Add `pricing.rs` with per-model pricing table (gpt-4.1, gpt-4o, o3, o4-mini, etc.) and prefix-matching for date-suffixed model slugs - Track cumulative cost across the session via `Rc<Cell<f64>>` shared between `ThreadActor` and `PromptState` - Compute incremental cost from `last_token_usage` on each `TokenCountEvent`, using the active model's pricing - Update model tracking on `ModelReroute` events so mid-session model switches are priced correctly - For unknown models, cost is omitted (remains `None`) This is an interim solution until the upstream Codex event stream exposes authoritative cost (openai/codex#16258). Closes zed-industries#209 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Populate
UsageUpdate.costwith an estimated cumulative session cost derived from per-turn token counts and a model pricing table.pricing.rswith per-model pricing for gpt-4.1, gpt-4o, o3, o4-mini families and prefix-matching for date-suffixed model slugsRc<Cell<f64>>shared betweenThreadActorandPromptStatelast_token_usageon eachTokenCountEventModelRerouteevents so mid-session model switches are priced correctlyNone)This is an interim solution until the upstream Codex event stream exposes authoritative cost (openai/codex#16258).
Caveats (documented in #209):
Closes #209
Test plan
UsageUpdatenotifications includecostwithamount > 0andcurrency: "USD"for known modelscostis omitted for unknown modelspricing.rspass🤖 Generated with Claude Code