Class Usage


public class Usage extends ObjectWithJsonToString
Token usage for an LLM completion.

inputTokens and outputTokens are the baseline counts every provider reports. The remaining fields are optional — when a provider does not report them they stay null and behaviour is unchanged (back-compatible):

  • cachedInputTokens — input tokens served from a prompt cache at a reduced rate. Maps to OpenAI prompt_tokens_details.cached_tokens and Anthropic cache_read_input_tokens. These are a subset of inputTokens (not additive) for both providers.
  • cacheCreationTokens — input tokens written to a prompt cache at a premium rate. Maps to Anthropic cache_creation_input_tokens.
  • reasoningTokens — "thinking"/reasoning tokens that are billed as output but not part of the visible completion. Maps to OpenAI completion_tokens_details.reasoning_tokens. These are a subset of outputTokens (not additive).

Cost dashboards that ignore these fields mis-bill cached and reasoning-heavy workloads; surfacing them lets a downstream consumer apply the provider's cache-read discount or attribute reasoning spend.

  • Constructor Details

    • Usage

      public Usage()
  • Method Details

    • usage

      public static Usage usage()
    • inputTokens

      public static Usage inputTokens(int inputTokens)
    • outputTokens

      public static Usage outputTokens(int outputTokens)
    • withInputTokens

      public Usage withInputTokens(Integer inputTokens)
    • getInputTokens

      public Integer getInputTokens()
    • withOutputTokens

      public Usage withOutputTokens(Integer outputTokens)
    • getOutputTokens

      public Integer getOutputTokens()
    • withCachedInputTokens

      public Usage withCachedInputTokens(Integer cachedInputTokens)
      Input tokens served from a prompt cache (OpenAI prompt_tokens_details.cached_tokens / Anthropic cache_read_input_tokens). A subset of getInputTokens().
    • getCachedInputTokens

      public Integer getCachedInputTokens()
    • withCacheCreationTokens

      public Usage withCacheCreationTokens(Integer cacheCreationTokens)
      Input tokens written to a prompt cache (Anthropic cache_creation_input_tokens).
    • getCacheCreationTokens

      public Integer getCacheCreationTokens()
    • withReasoningTokens

      public Usage withReasoningTokens(Integer reasoningTokens)
      Reasoning/thinking tokens billed as output but not part of the visible completion (OpenAI completion_tokens_details.reasoning_tokens). A subset of getOutputTokens().
    • getReasoningTokens

      public Integer getReasoningTokens()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class ObjectWithReflectiveEqualsHashCodeToString
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class ObjectWithReflectiveEqualsHashCodeToString