fix: preserve cached and reasoning tokens without double billing - #140
Merged
tishachawla-jg merged 1 commit intoSep 16, 2026
Merged
tishachawla-jg merged 1 commit into
tishachawla-jg merged 1 commit into
Conversation
Contributor
Author
|
The implementation and all local default tests/lint/type checks are complete. GitHub is waiting for maintainer approval to run the CI workflow for this contribution. Please enable it when reviewing the PR; I can address any resulting failures. |
tishachawla-jg
approved these changes
Sep 16, 2026
6 tasks
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.
Cache-read and reasoning counts were dropped before reaching pricing. This inflated the issue's OpenAI-compatible high-cache fixture from 156,204 to 461,258 microdollars; native Anthropic instead lost the cache-read charge.
Normalize SDK responses and flat agent-step/dispatch counts into disjoint
Usagebuckets exactly once.inputexcludes cached reads andoutputexcludes reasoning; flatModelResponse/step counts remain inclusive totals. Populate both bundled adapters, account for native Anthropic's already-disjoint input, and preserve total prompt size in context-compaction trends. Document the contract and migration inUsage,ModelResponse, and the changelog. Pricing itself is unchanged.Validation:
python -m pytest -q: 244 passed, 43 skipped, 1 live test deselected; one dependency deprecation warning.ruff check src tests examples,ruff format --check src tests examples, andmypy src/tokenopspass (58 source files).git diff --checkpasses.No live provider calls or original SWE-bench rerun. Cache-write premiums, streaming usage, additional adapters and context-compaction capabilities remain out of scope. The change to the compaction detector only retains its existing total-context semantics after separating cache reads.
Fixes #137. Follows the provider-aware approach discussed and approved in the issue.