Repository navigation
Serve a session's token usage per assistant message - #208
Merged
Merged
Conversation
GET /v1/sessions/:id/usage returns an { entryId, usage } pair for each
assistant message that carries usage, in seq order. An errored or
aborted message carries none, so the list is the usage a session is
charged for.
The read is a new Store method, readUsage, filtered and projected in
SQL: only assistant rows match, and only their id and usage leave the
database, so the tool results that make up most of a log are never
shipped to the api or parsed there. Covered by the store conformance
suite and the route tests.
Co-Authored-By: Claude Opus 5.5 (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.
Adds
GET /v1/sessions/:id/usage, which returns an{ entryId, usage }pair for each assistant message that carries usage, in seq order; errored and aborted messages carry none, so the list is the usage a session is charged for. The read is a new Store method,readUsage, filtered and projected in SQL so only assistant rows' id and usage leave the database, never the tool results that make up most of a log. It is covered by a new store conformance case (roles, missing usage, seq order, foreign namespace) and route tests (pairs, empty session, 404s). Fullpnpm test, typecheck and prettier pass; one crash-resume test timed out once under the parallel run and passed on every rerun.🤖 Generated with Claude Code