ModelUsage

org.llm4s.agent.ModelUsage
See theModelUsage companion object
case class ModelUsage(requestCount: Long, inputTokens: Long, outputTokens: Long, thinkingTokens: Long, totalCost: BigDecimal)

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

Attributes

Companion
object
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

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

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product