Skip to content

fix: report per-request Anthropic usage in chat token accounting - #27966

Open
ibetitsmike wants to merge 1 commit into
mainfrom
mike/fantasy-per-request-usage-pin
Open

fix: report per-request Anthropic usage in chat token accounting#27966
ibetitsmike wants to merge 1 commit into
mainfrom
mike/fantasy-per-request-usage-pin

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Anthropic can report input and cache usage cumulatively in the final message_delta when one request runs multiple internal iterations. Pin charm.land/fantasy to coder/fantasy#50 so the Finish part uses the request's message_start input and cache values while retaining cumulative output tokens.

Add a chatd regression test that streams distinct message_start and final message_delta usage and verifies that the persisted assistant message keeps the per-request values. The chattest fake now supports independent start and delta usage, and its tool-call stream emits usage in Anthropic's event shape.

The pin currently points at coder/fantasy#50's branch head and will be re-pinned to the merged SHA once coder/fantasy#50 lands.

Mux acted on Mike's behalf to author this change.

@ibetitsmike
ibetitsmike marked this pull request as ready for review August 10, 2026 06:21
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 982cb24c03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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