UsageSummary

org.llm4s.agent.UsageSummary
See theUsageSummary companion object
case class UsageSummary(requestCount: Long, inputTokens: Long, outputTokens: Long, thinkingTokens: Long, totalCost: BigDecimal, byModel: Map[String, ModelUsage])

Aggregates token and cost statistics across all models used in an agent run.

The top-level fields (requestCount, inputTokens, etc.) are roll-ups across every model. The byModel map breaks the same figures down per model name (e.g. "claude-sonnet-4-5-latest", "gpt-4o"), allowing cost attribution per provider in multi-model pipelines.

totalCost uses BigDecimal rather than Double to keep cumulative sums deterministic regardless of the number of requests.

Value parameters

byModel

per-model breakdown; keyed by the model identifier string

inputTokens

total prompt tokens sent across all models

outputTokens

total completion tokens received across all models

requestCount

total API calls across all models

thinkingTokens

total extended-thinking tokens (non-zero only for Anthropic models)

totalCost

total estimated cost in USD; BigDecimal(0) when unavailable

Attributes

See also

ModelUsage for the per-model record type

org.llm4s.agent.AgentState which carries a UsageSummary for the whole run

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(model: String, usage: TokenUsage, cost: Option[Double]): UsageSummary

Returns a new UsageSummary with the given usage record folded in.

Returns a new UsageSummary with the given usage record folded in.

Creates a new ModelUsage entry for model if one does not yet exist.

Value parameters

cost

optional estimated cost in USD; treated as zero when absent

model

model identifier string (e.g. "gpt-4o")

usage

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

Attributes

Combines two UsageSummary records by summing every field and merging the per-model maps.

Combines two UsageSummary records by summing every field and merging the per-model maps.

Use this when aggregating results from parallel sub-agents or separate pipeline stages into a single top-level summary.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product