Repository navigation
Report the price back onto the bus - #21
Merged
Merged
Conversation
The store is the only place in the chain that knows what a request cost — the gateway knows how many tokens went by, the per-token rate is looked up here when the row is written. So the price arrives a moment after the request finishes, and nothing announced it. Anything wanting to show a figure had to go back and query for it after the fact. In the desktop client that is a re-read of the last two hundred rows a couple of seconds after every batch of requests, kept alive purely because this one number was missing from the stream. A live chart cannot use that at all. `RequestPriced` is a separate event rather than a field on `RequestFinished` on purpose: putting it there would make the gateway depend on the price table, which files "forwarding" under "billing". The recorder gets an optional bus handle and reports what it computed; twcore does the wiring, being the one place that sees both sides. All three values stay optional. Upstream returned no usage, the model is absent from the table, the provider bills by subscription — none of those is zero, and a zero would be drawn as "free". 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
The store is the only place in the chain that knows what a request cost: the gateway knows how many tokens went by, and the per-token rate is looked up here when the row is written. So the price is known a moment after the request finishes — and nothing announced it.
Anything that wants to display a figure has to go back and query for it. In the desktop client that means re-reading the last two hundred rows a couple of seconds after every batch of requests, a mechanism that exists purely because this one number is missing from the stream. A live chart cannot use it at all.
What
Event::RequestPriced { id, cost_micros, cost_estimated, cache_saved_micros, at_ms }.A separate event rather than a field on
RequestFinished, deliberately: putting it there would make the gateway depend on the price table, filing "forwarding" under "billing". The recorder takes an optional bus handle (Recorder::reporting_to) and reports what it computed;twcoredoes the wiring, being the one place that sees both sides. The recorder ignores the variant it emits, so there is no loop.All three values stay
Option. Upstream returned no usage, the model is absent from the table, the provider bills by subscription — none of those is zero, and a zero gets drawn as "free".Gates
cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace(61 binaries green, 2 new),./scripts/smoke.sh(46 passed, 0 failed).🤖 Generated with Claude Code