add_usage#
- langchain_core.messages.ai.add_usage(left: UsageMetadata | None, right: UsageMetadata | None) UsageMetadata [source]#
Recursively add two UsageMetadata objects.
Example
from langchain_core.messages.ai import add_usage left = UsageMetadata( input_tokens=5, output_tokens=0, total_tokens=5, input_token_details=InputTokenDetails(cache_read=3) ) right = UsageMetadata( input_tokens=0, output_tokens=10, total_tokens=10, output_token_details=OutputTokenDetails(reasoning=4) ) add_usage(left, right)
results in
UsageMetadata( input_tokens=5, output_tokens=10, total_tokens=15, input_token_details=InputTokenDetails(cache_read=3), output_token_details=OutputTokenDetails(reasoning=4) )
- Parameters:
left (UsageMetadata | None)
right (UsageMetadata | None)
- Return type: