Skip to content

Serve a session's token usage per assistant message - #208

Merged
jinxi97 merged 1 commit into
mainfrom
jinxi97/funky-s-db-token-costs
Oct 26, 2026
Merged

jinxi97 merged 1 commit into
mainfrom
jinxi97/funky-s-db-token-costs

Conversation

@jinxi97

@jinxi97 jinxi97 commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

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). Full pnpm 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

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>
@jinxi97
jinxi97 merged commit e953718 into main Oct 26, 2026
3 checks passed
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