LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coremessagesaiUsageMetadata
    Classā—Since v0.2

    UsageMetadata

    Copy
    UsageMetadata()

    Bases

    TypedDict

    Constructors

    Attributes

    View source on GitHub
    constructor
    __init__
    NameType
    input_tokensint
    output_tokensint
    total_tokensint
    input_token_detailsNotRequired[InputTokenDetails]
    output_token_detailsNotRequired[OutputTokenDetails]
    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.

    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 langchain-core 0.3.9

    Added input_token_details and output_token_details.

    LangSmith SDK

    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.