Usage metadata for a message, such as token counts.
public Optional<UsageMetadata> usageMetadata()Usage metadata for a message, such as token counts. This is a standard representation of token usage that is consistent across models. Example:
{
"input_tokens": 350,
"output_tokens": 240,
"total_tokens": 590,
"input_token_details": {
"audio": 10,
"cache_creation": 200,
"cache_read": 100,
},
"output_token_details": {
"audio": 10,
"reasoning": 200,
},
}
"Behavior changed in 0.3.9" Added input_token_details and
output_token_details.
LangChainInvalidDataException: if the JSON field has an unexpected type (e.g.
if the server responded with an unexpected value).