Usage metadata for a message, such as token counts.
This is a standard representation of token usage that is consistent across models.
UsageMetadata()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,
},
}
langchain-core 0.3.9Added input_token_details and output_token_details.
The LangSmith SDK also has a UsageMetadata class. While the two share fields,
LangSmith's UsageMetadata has additional fields to capture cost information
used by the LangSmith platform.
| Name | Type |
|---|---|
| input_tokens | int |
| output_tokens | int |
| total_tokens | int |
| input_token_details | NotRequired[InputTokenDetails] |
| output_token_details | NotRequired[OutputTokenDetails] |
Count of input (or prompt) tokens. Sum of all input token types.
Count of output (or completion) tokens. Sum of all output token types.
Total token count. Sum of input_tokens + output_tokens.
Breakdown of input token counts.
Does not need to sum to full input token count. Does not need to have all keys.
Breakdown of output token counts.
Does not need to sum to full output token count. Does not need to have all keys.