Claude Streaming Usage Metadata Missing or Wrong
You need token counts for billing/analytics but the streaming response arrives without usage data — or the counts don't match what you expect. Usage is split across message_start (input tokens) and message_delta (output tokens), NOT sent per-chunk.
Input tokens arrive in message_start.message.usage. Output tokens arrive in message_delta.usage.output_tokens (near end of stream). Cache metrics (cache_creation_input_tokens, cache_read_input_tokens) are in message_start. Track both events to get the full picture.
The Symptoms You're Seeing
usage.output_tokens is 0 or missing after stream ends → You looked at message_start; output count is in message_delta Billing dashboard shows higher tokens than my logs → You forgot to include cache_read_input_tokens Streaming response.usage doesn't match non-streaming response.usage → Only if you're accumulating incorrectly; totals should match Only got input_tokens, no output_tokens → Stream was interrupted before message_delta arrived cache_creation_input_tokens is None → Prompt caching not used on this request (this is fine)
Where Usage Data Lives in the Stream
What Actually Causes This Error
Fixes That Work (Tested Nov 2026)
1SDK Approach (Recommended)
2Manual Usage Tracking (Custom Parser)
3Reconcile With Anthropic Billing Dashboard
Input: $3.00 per 1M tokens
Output: $15.00 per 1M tokens
Cache write: $3.75 per 1M tokens (5-min ephemeral cache)
Cache read: $0.30 per 1M tokens (10% of input price)
All four token types are billable. If your logs miss any category, dashboard totals won't match. Server-side tool use (computer use, web search) has separate billing lines.
Preventing This Error Going Forward
- Log usage after every stream. Store all four token categories.
- Use SDK's
get_final_message(). Handles aggregation for you. - Include cache tokens in cost dashboards. Ignoring them = wrong forecasts.
- Emit usage on interrupted streams too. Whatever you have from message_start is still billed.
- Reconcile monthly with Anthropic Console. Discrepancy > 5% suggests parsing bug.
Researcher · AI Error Hub
Frequently Asked Questions
It's a placeholder — Anthropic accounts for the first output token to be generated. The real count is finalized in message_delta once generation completes. Never trust message_start.usage.output_tokens as final.
No. To estimate live cost while streaming, count text_delta events or use tiktoken-style estimation. The authoritative count arrives only in message_delta at the end.
For server-side tools (web_search, code_execution, computer use), Anthropic reports additional token fields like server_tool_use.web_search_requests or server_tool_use.execution_time_ms. These are billed at published rates for each tool. Include them in cost tracking if you use these tools.
Yes. Cache reads bill at 10% of the input rate. So cache_read_input_tokens × input_price × 0.10. The API doesn't charge the full input rate for cached content — you just need to include it in your cost math.
Yes, whatever tokens were consumed are billed. Refusals may generate a short output (billed), and input tokens are always billed even on 400 errors after processing began.
Related Errors
Track Every Token With Confidence
Weekly deep dives on Claude cost management, prompt caching optimization, and billing reconciliation. 12,000+ developers subscribe.
Subscribe Free →