UsageMetadata()| Name | Type |
|---|---|
| input_tokens | int |
| output_tokens | int |
| total_tokens | int |
| input_token_details | NotRequired[InputTokenDetails] |
| output_token_details | NotRequired[OutputTokenDetails] |
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,
},
}
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.