You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AnthropicLlm usage_metadata is missing thinking token count #5397
AnthropicLlm only maps basic input/output token counts into usage_metadata. When extended thinking is enabled, thinking block tokens are included in output_tokens but never broken out separately.
Current behaviour
message_to_generate_content_response and the streaming final response both produce:
Cache token counts (cache_creation_input_tokens, cache_read_input_tokens) are also missing but are tracked separately in #5395.
Expected behaviour
When extended thinking is enabled, populate usage_metadata.thoughts_token_count with the token count of thinking blocks. This is derivable from the thinking block content (supplemental API call to tokenizer) or from a future dedicated API field (ref: anthropic-python-sdk ).
Reference
This is particularly relevant now that extended thinking is supported via PR #5392.
The premise for closing this issue has changed: the current Anthropic Messages
API now provides an exact thinking-token breakdown through usage.output_tokens_details.thinking_tokens.
with OutputTokensDetails.thinking_tokens: int. I verified these types with anthropic==0.120.2.
The breakdown is still discarded by google-adk==2.6.2:
In the non-streaming path, message_to_generate_content_response() maps
the inclusive message.usage.output_tokens directly to candidates_token_count without reading output_tokens_details.
In the streaming path, _generate_content_streaming() reads only event.usage.output_tokens from the final message_delta, so it also loses output_tokens_details.thinking_tokens.
To preserve GenerateContentResponseUsageMetadata semantics without
double-counting, I believe the mapping should be:
BQ Agent Analytics already exposes usage_metadata.thoughts_token_count, so preserving the value in LlmResponse.usage_metadata would also complete the existing analytics path
for Claude without provider-specific BigQuery logic.
Could this issue be reopened now that Anthropic provides the exact field? I
would be happy to help validate the streaming and non-streaming behavior.
Activity
llalitkumarrr commentedon Apr 20, 2026
Hello @sebastienc ,
Thank you for bringing this to our attention. If you have a solution in mind for this issue, would you be willing to contribute a fix?
sebastienc commentedon Apr 20, 2026
I see three options.
Which one would you prefer?
I'd be happy to implement.
sasha-gitg commentedon May 1, 2026
Since this isn't available through the Anthropic API we will not support this feature.
lmandrelli commentedon Aug 7, 2026
The premise for closing this issue has changed: the current Anthropic Messages
API now provides an exact thinking-token breakdown through
usage.output_tokens_details.thinking_tokens.Anthropic documents the field here:
https://platform.claude.com/docs/en/build-with-claude/extended-thinking#pricing
The current Python SDK models it in both response paths:
anthropic.types.Usage.output_tokens_detailsanthropic.types.MessageDeltaUsage.output_tokens_detailswith
OutputTokensDetails.thinking_tokens: int. I verified these types withanthropic==0.120.2.The breakdown is still discarded by
google-adk==2.6.2:message_to_generate_content_response()mapsthe inclusive
message.usage.output_tokensdirectly tocandidates_token_countwithout readingoutput_tokens_details._generate_content_streaming()reads onlyevent.usage.output_tokensfrom the finalmessage_delta, so it also losesoutput_tokens_details.thinking_tokens.To preserve
GenerateContentResponseUsageMetadatasemantics withoutdouble-counting, I believe the mapping should be:
Anthropic's
output_tokensremains the inclusive, authoritative billed-outputtotal.
If
output_tokens_detailsis absent, a cost-safe fallback would retain thecurrent mapping:
BQ Agent Analytics already exposes
usage_metadata.thoughts_token_count, so preserving the value inLlmResponse.usage_metadatawould also complete the existing analytics pathfor Claude without provider-specific BigQuery logic.
Could this issue be reopened now that Anthropic provides the exact field? I
would be happy to help validate the streaming and non-streaming behavior.