LLMConsumption

@Serializable(with = LLMConsumptionSerializer::class)
abstract class LLMConsumption

Base type for an amount of LLM consumption recorded during an optimization run.

This is an abstract class (not sealed) so that providers outside the library can define their own consumption flavors. Each flavor pairs with an LLMConsumptionUnit and registers a decoder via LLMConsumptionType (discovered through LLMConsumptionRegistry); serialization is handled uniformly by LLMConsumptionSerializer.

Inheritors

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
abstract val total: Double

The single scalar total used for comparisons (e.g. against a spend cap).

Link copied to clipboard
abstract val unit: LLMConsumptionUnit

The unit this consumption is measured in.

Functions

Link copied to clipboard
abstract operator fun plus(consumption: LLMConsumption): LLMConsumption

Adds two consumptions of the same flavor. Implementations reject mismatched flavors.

Link copied to clipboard
abstract fun toPrettyJson(): JsonObject

The flavor-specific fields as pretty JSON (without the top-level "unit" field).

Link copied to clipboard
abstract fun toPrettyString(): String

Human-readable form, typically with input/output breakdown where applicable.

Link copied to clipboard

Total-only short form, e.g. "330,329.00 tokens" / "150.00 credits". Used where the input/output breakdown would be misleading or off-topic — most notably the spend-limit abort message, where there is no such thing as a separate input/output cap (cap is a single total).