fix: report per-request Anthropic usage in chat token accounting - #27966
Conversation
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
982cb24 to
70b426e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Anthropic can report input and cache usage cumulatively in the final
message_deltawhen one request runs multiple internal iterations. Pincharm.land/fantasyto coder/fantasy#50 so the Finish part uses the request'smessage_startinput and cache values while retaining cumulative output tokens.The v0.40.0 upstream sync (coder/fantasy#51, pinned on main by #27981) does not cover this: the SDK fork's delta-field merge is unchanged at the new pin, and
TestActiveServer_AnthropicPersistsPerRequestUsagefails against main's pin with the inflated cumulative value (287682 instead of 139956).Add a chatd regression test that streams distinct
message_startand finalmessage_deltausage 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 (
02fe208, the fix rebased onto the v0.40.0 sync) and will be re-pinned to the merged SHA once coder/fantasy#50 lands.