fix(proxy): estimate streamed output from content - #3020
Open
JerrettDavis wants to merge 2 commits into
Open
Conversation
Contributor
PR governanceThis PR follows the template and is marked ready for human review. |
JerrettDavis
force-pushed
the
fix/stream-output-token-accounting
branch
from
August 14, 2026 04:52
35283c2 to
618551b
Compare
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
JerrettDavis
marked this pull request as ready for review
August 14, 2026 05:02
JerrettDavis
requested review from
DevanshiVyas and
chopratejas
as code owners
August 14, 2026 05:03
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.
Description
Replace the streaming fallback that estimates completion tokens from the entire SSE envelope with provider-aware counting of the generated content itself. This prevents event names, JSON metadata, identifiers, and chunk framing from distorting model-output accounting when an upstream omits usage.
Closes #2712
Type of Change
Changes Made
estimated_bytesaccounting tag withestimated_contentand add cross-provider regression coverage.Testing
pytest)ruff check .)mypy headroom)Test Output
Real Behavior Proof
bbe901319.Hello thereplus 80 KB of envelope metadata, then finalize a no-usage stream with 500 KB of framing and eight one-character content deltas.Runtime Rollout Safety
Review Readiness
Checklist
CHANGELOG.md— it is generated by release-please from my Conventional Commit PR title (a CI guard enforces this)Screenshots (if applicable)
Not applicable; this changes streaming usage accounting only.
Additional Notes
The prior
bytes // 40heuristic counted the protocol envelope rather than model output and could be arbitrarily distorted by metadata or chunk framing. The new fallback is bounded to content the provider actually generated.