PRODUCTION SCENARIO
A web service streams Claude responses to browsers and must record the output tokens generated per response for customer chargeback.
Which server-sent event carries the final output token count?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: The message_delta event that precedes message_stop
message_delta carries the cumulative usage and the stop_reason as generation finishes, so its last occurrence holds the final output token count. message_start reports input tokens and a small non-zero output count before any text exists. content_block_delta events carry content only and have no usage field to sum. message_stop closes the stream and carries no usage of its own.
Official Source: https://platform.claude.com/docs/en/build-with-claude/streaming ↗