LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
  • RemoteGraph
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDKRemoteGraph
Language
Theme
PythonlangsmithschemasUsageMetadata
Class●Since v0.1

UsageMetadata

Usage metadata for a message, such as token counts.

This is a standard representation of token usage that is consistent across models.

Copy
UsageMetadata()

Bases

TypedDict

Constructors

constructor
__init__
NameType
input_tokensint
output_tokensint
total_tokensint
input_token_detailsNotRequired[InputTokenDetails]
output_token_detailsNotRequired[OutputTokenDetails]
input_costNotRequired[float]
output_costNotRequired[float]
total_costNotRequired[float]
input_cost_detailsNotRequired[InputCostDetails]
output_cost_detailsNotRequired[OutputCostDetails]

Attributes

attribute
input_tokens: int

Count of input (or prompt) tokens. Sum of all input token types.

attribute
output_tokens: int

Count of output (or completion) tokens. Sum of all output token types.

attribute
total_tokens: int

Total token count. Sum of input_tokens + output_tokens.

attribute
input_token_details: NotRequired[InputTokenDetails]

Breakdown of input token counts.

Does not need to sum to full input token count. Does not need to have all keys.

attribute
output_token_details: NotRequired[OutputTokenDetails]

Breakdown of output token counts.

Does not need to sum to full output token count. Does not need to have all keys.

attribute
input_cost: NotRequired[float]

The cost of the input tokens.

attribute
output_cost: NotRequired[float]

The cost of the output tokens.

attribute
total_cost: NotRequired[float]

The total cost of the tokens.

attribute
input_cost_details: NotRequired[InputCostDetails]

The cost details of the input tokens.

attribute
output_cost_details: NotRequired[OutputCostDetails]

The cost details of the output tokens.

View source on GitHub