Package com.tnsai.llm.observability
Record Class TokenUsage
java.lang.Object
java.lang.Record
com.tnsai.llm.observability.TokenUsage
public record TokenUsage(long promptTokens, long completionTokens, long cachedTokens, long reasoningTokens, long totalTokens)
extends Record
Token-count breakdown for one LLM call (issue #79).
Modern provider APIs (OpenAI o1, Anthropic Claude with thinking,
prompt-caching APIs) report token counts split by purpose. cachedTokens
captures prompt tokens served from a provider-side cache (priced lower);
reasoningTokens captures reasoning-pass tokens for "thinking"
models that count separately from the final completion. totalTokens
is provider-reported when available, otherwise the caller computes it
as promptTokens + completionTokens + reasoningTokens.
- Since:
- 0.5.0 (issue #79)
-
Constructor Summary
ConstructorsConstructorDescriptionTokenUsage(long promptTokens, long completionTokens, long cachedTokens, long reasoningTokens, long totalTokens) Creates an instance of aTokenUsagerecord class. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the value of thecachedTokensrecord component.longReturns the value of thecompletionTokensrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static TokenUsageof(long promptTokens, long completionTokens) Convenience: minimal usage with only prompt + completion.longReturns the value of thepromptTokensrecord component.longReturns the value of thereasoningTokensrecord component.final StringtoString()Returns a string representation of this record class.longReturns the value of thetotalTokensrecord component.static TokenUsagezero()Convenience: zero usage — placeholder for failed calls.
-
Constructor Details
-
TokenUsage
public TokenUsage(long promptTokens, long completionTokens, long cachedTokens, long reasoningTokens, long totalTokens) Creates an instance of aTokenUsagerecord class.- Parameters:
promptTokens- the value for thepromptTokensrecord componentcompletionTokens- the value for thecompletionTokensrecord componentcachedTokens- the value for thecachedTokensrecord componentreasoningTokens- the value for thereasoningTokensrecord componenttotalTokens- the value for thetotalTokensrecord component
-
-
Method Details
-
of
Convenience: minimal usage with only prompt + completion. -
zero
Convenience: zero usage — placeholder for failed calls. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
promptTokens
public long promptTokens()Returns the value of thepromptTokensrecord component.- Returns:
- the value of the
promptTokensrecord component
-
completionTokens
public long completionTokens()Returns the value of thecompletionTokensrecord component.- Returns:
- the value of the
completionTokensrecord component
-
cachedTokens
public long cachedTokens()Returns the value of thecachedTokensrecord component.- Returns:
- the value of the
cachedTokensrecord component
-
reasoningTokens
public long reasoningTokens()Returns the value of thereasoningTokensrecord component.- Returns:
- the value of the
reasoningTokensrecord component
-
totalTokens
public long totalTokens()Returns the value of thetotalTokensrecord component.- Returns:
- the value of the
totalTokensrecord component
-