feat(server): report usage on the final stream chunk #50
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/stream-usage"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Streaming responses carried no token accounting: usage only existed on
the non-streaming response shapes. A client (or an aggregating proxy,
which is the motivating case) reassembling a stream into a plain
response had nothing to carry over.
Both /v1/completions and /v1/chat/completions now set usage on the
final chunk -- the same values the non-streaming response would have
carried -- and only there, so delta chunks are unchanged.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Automated review by pr-reviewer v0.37.0 | Safety Check | Claude Sonnet 5 | tracking id
r-6157af-194a72This is an AI-generated review and may contain mistakes.
Status: ✅ Completed
✅ Verdict: LGTM — Small, well-tested feature addition with no signs of bugs or security issues.
Straightforward, well-scoped change: adds a
Usagepointer field to both streaming chunk types and populates it only on the final SSE chunk via an existingusage(res)helper, mirroring non-streaming behavior. Tests were updated to assert usage is present only on the last chunk and absent elsewhere for both completions and chat completions endpoints. No signs of leaked secrets, injection risk, or breaking changes —omitemptykeeps the field backward-compatible for clients not expecting it. Diff is small and consistent with the stated intent.b51b9c75f819d4ca806b