Package akka.javasdk.agent
Record Class Agent.TokenUsage
- Record Components:
inputTokens- the input token count as the provider reports itoutputTokens- tokens in the response returned by the modelcacheReadInputTokens- prompt tokens served from the provider's prompt cache, or 0 when the provider reports nothingcacheWriteInputTokens- prompt tokens written to the provider's prompt cache, or 0 when the provider reports nothingtotalInputTokens- every prompt token the interaction consumed, counted once, whatever the provider
- Enclosing class:
Agent
public static record Agent.TokenUsage(int inputTokens, int outputTokens, int cacheReadInputTokens, int cacheWriteInputTokens, int totalInputTokens)
extends Record
The number of tokens consumed by a model interaction.
Providers differ on whether inputTokens includes cached prompt tokens. Use
totalInputTokens for a count that does not depend on the provider.
totalInputTokens counts cached prompt tokens at full weight. It is not weighted by
cost, and providers bill cache reads and cache writes at rates that differ from regular input
tokens.
A totalInputTokens of 0 is replaced by inputTokens. This also applies to
JSON that was written before the field existed.
-
Constructor Summary
ConstructorsConstructorDescriptionTokenUsage(int inputTokens, int outputTokens) A usage with no prompt cache activity.TokenUsage(int inputTokens, int outputTokens, int cacheReadInputTokens, int cacheWriteInputTokens, int totalInputTokens) Creates an instance of aTokenUsagerecord class. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thecacheReadInputTokensrecord component.intReturns the value of thecacheWriteInputTokensrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intReturns the value of theinputTokensrecord component.intReturns the value of theoutputTokensrecord component.final StringtoString()Returns a string representation of this record class.intReturns the value of thetotalInputTokensrecord component.
-
Constructor Details
-
TokenUsage
public TokenUsage(int inputTokens, int outputTokens, int cacheReadInputTokens, int cacheWriteInputTokens, int totalInputTokens) Creates an instance of aTokenUsagerecord class.- Parameters:
inputTokens- the value for theinputTokensrecord componentoutputTokens- the value for theoutputTokensrecord componentcacheReadInputTokens- the value for thecacheReadInputTokensrecord componentcacheWriteInputTokens- the value for thecacheWriteInputTokensrecord componenttotalInputTokens- the value for thetotalInputTokensrecord component
-
TokenUsage
public TokenUsage(int inputTokens, int outputTokens) A usage with no prompt cache activity.
-
-
Method Details
-
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 '=='. -
inputTokens
public int inputTokens()Returns the value of theinputTokensrecord component.- Returns:
- the value of the
inputTokensrecord component
-
outputTokens
public int outputTokens()Returns the value of theoutputTokensrecord component.- Returns:
- the value of the
outputTokensrecord component
-
cacheReadInputTokens
public int cacheReadInputTokens()Returns the value of thecacheReadInputTokensrecord component.- Returns:
- the value of the
cacheReadInputTokensrecord component
-
cacheWriteInputTokens
public int cacheWriteInputTokens()Returns the value of thecacheWriteInputTokensrecord component.- Returns:
- the value of the
cacheWriteInputTokensrecord component
-
totalInputTokens
public int totalInputTokens()Returns the value of thetotalInputTokensrecord component.- Returns:
- the value of the
totalInputTokensrecord component
-