Package com.tnsai.llm.observability
Record Class CostEstimate
java.lang.Object
java.lang.Record
com.tnsai.llm.observability.CostEstimate
public record CostEstimate(BigDecimal promptUSD, BigDecimal completionUSD, BigDecimal cachedDiscountUSD, BigDecimal reasoningUSD, BigDecimal totalUSD, String pricingTableVersion)
extends Record
USD cost breakdown for one LLM call (issue #79).
Computed by an LLMPricingRegistry from TokenUsage +
the call's provider/model. Records the
pricingTableVersion that produced the estimate so historical
costs aren't retroactively recomputed when rates change downstream.
Field semantics
promptUSD— the billed prompt cost, i.e. cached tokens already moved to the discounted rate. For a call with no caching, this is justpromptTokens × rate / 1000.completionUSD— billed completion cost.reasoningUSD— billed reasoning-pass cost (typically zero for non-reasoning models).cachedDiscountUSD— positive number recording how much caching saved versus the full prompt rate. Not subtracted fromtotalUSDagain — the savings are already reflected inpromptUSD.totalUSD— what the caller actually pays:promptUSD + cachedAtCachedRate + completionUSD + reasoningUSDwherecachedAtCachedRateis folded into the total but not exposed as its own field (consumers that want it can derivetotalUSD - promptUSD - completionUSD - reasoningUSD).
- Since:
- 0.5.0 (issue #79)
-
Constructor Summary
ConstructorsConstructorDescriptionCostEstimate(BigDecimal promptUSD, BigDecimal completionUSD, BigDecimal cachedDiscountUSD, BigDecimal reasoningUSD, BigDecimal totalUSD, String pricingTableVersion) Creates an instance of aCostEstimaterecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thecachedDiscountUSDrecord component.Returns the value of thecompletionUSDrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of thepricingTableVersionrecord component.Returns the value of thepromptUSDrecord component.Returns the value of thereasoningUSDrecord component.final StringtoString()Returns a string representation of this record class.totalUSD()Returns the value of thetotalUSDrecord component.static CostEstimateConvenience: zero-cost estimate — useful for failed calls or local models.
-
Constructor Details
-
CostEstimate
public CostEstimate(BigDecimal promptUSD, BigDecimal completionUSD, BigDecimal cachedDiscountUSD, BigDecimal reasoningUSD, BigDecimal totalUSD, String pricingTableVersion) Creates an instance of aCostEstimaterecord class.- Parameters:
promptUSD- the value for thepromptUSDrecord componentcompletionUSD- the value for thecompletionUSDrecord componentcachedDiscountUSD- the value for thecachedDiscountUSDrecord componentreasoningUSD- the value for thereasoningUSDrecord componenttotalUSD- the value for thetotalUSDrecord componentpricingTableVersion- the value for thepricingTableVersionrecord component
-
-
Method Details
-
zero
Convenience: zero-cost estimate — useful for failed calls or local models. -
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 withObjects::equals(Object,Object). -
promptUSD
Returns the value of thepromptUSDrecord component.- Returns:
- the value of the
promptUSDrecord component
-
completionUSD
Returns the value of thecompletionUSDrecord component.- Returns:
- the value of the
completionUSDrecord component
-
cachedDiscountUSD
Returns the value of thecachedDiscountUSDrecord component.- Returns:
- the value of the
cachedDiscountUSDrecord component
-
reasoningUSD
Returns the value of thereasoningUSDrecord component.- Returns:
- the value of the
reasoningUSDrecord component
-
totalUSD
Returns the value of thetotalUSDrecord component.- Returns:
- the value of the
totalUSDrecord component
-
pricingTableVersion
Returns the value of thepricingTableVersionrecord component.- Returns:
- the value of the
pricingTableVersionrecord component
-