ModelUsage

org.llm4s.llmconnect.model.ModelUsage
See theModelUsage companion object
@Stable
final case class ModelUsage

Accumulates token and cost statistics for a single model across one or more requests.

totalCost is stored as BigDecimal to avoid floating-point accumulation drift that would occur when summing many Double values; incoming Option[Double] costs are converted once via BigDecimal.decimal on first contact.

Value parameters

inputTokens

cumulative prompt tokens sent to the model

outputTokens

cumulative completion tokens received from the model

requestCount

number of API calls attributed to this model

thinkingTokens

cumulative extended-thinking tokens (Anthropic only; zero for other providers)

totalCost

cumulative estimated cost in USD; BigDecimal(0) when cost data is unavailable Build one with ModelUsage.apply and change it with the with* setters; the constructor and copy are private, so a new field never breaks callers. The constructor keeps its defaults because the JSON codec fills a missing key from them.

Attributes

Companion
object
Source
UsageSummary.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def add(usage: TokenUsage, cost: Option[Double]): ModelUsage

Returns a new ModelUsage with usage and cost folded in.

Returns a new ModelUsage with usage and cost folded in.

Value parameters

cost

optional estimated cost in USD; treated as zero when absent

usage

token-usage record from a org.llm4s.llmconnect.model.Completion

Attributes

Source
UsageSummary.scala
def merge(other: ModelUsage): ModelUsage

Combines two ModelUsage records by summing every field.

Combines two ModelUsage records by summing every field.

Useful when aggregating per-model statistics from parallel agent runs or multi-step pipelines where each step produces its own ModelUsage.

Attributes

Source
UsageSummary.scala
def withInputTokens(inputTokens: Long): ModelUsage

Sets the cumulative prompt tokens.

Sets the cumulative prompt tokens.

Attributes

Source
UsageSummary.scala
def withOutputTokens(outputTokens: Long): ModelUsage

Sets the cumulative completion tokens.

Sets the cumulative completion tokens.

Attributes

Source
UsageSummary.scala
def withRequestCount(requestCount: Long): ModelUsage

Sets the number of API calls attributed to this model.

Sets the number of API calls attributed to this model.

Attributes

Source
UsageSummary.scala
def withThinkingTokens(thinkingTokens: Long): ModelUsage

Sets the cumulative extended-thinking tokens.

Sets the cumulative extended-thinking tokens.

Attributes

Source
UsageSummary.scala

Sets the cumulative estimated cost in USD.

Sets the cumulative estimated cost in USD.

Attributes

Source
UsageSummary.scala

Inherited methods

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product