Getting the final output token count from a Claude stream

CCDV-F Applications & Integration Medium Question 41 of 105

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?

Show answer and explanation

CThe 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.

Source: platform.claude.com/docs/en/build-with-claude/streaming

Anonymous, no account needed. Your tally stays in this browser.

Next question Start 5 timed questions Browse all 105 original CCDV-F practice questions