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 just promptTokens × 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 from totalUSD again — the savings are already reflected in promptUSD.
  • totalUSD — what the caller actually pays: promptUSD + cachedAtCachedRate + completionUSD + reasoningUSD where cachedAtCachedRate is folded into the total but not exposed as its own field (consumers that want it can derive totalUSD - promptUSD - completionUSD - reasoningUSD).
Since:
0.5.0 (issue #79)
  • Constructor Details

    • CostEstimate

      public CostEstimate(BigDecimal promptUSD, BigDecimal completionUSD, BigDecimal cachedDiscountUSD, BigDecimal reasoningUSD, BigDecimal totalUSD, String pricingTableVersion)
      Creates an instance of a CostEstimate record class.
      Parameters:
      promptUSD - the value for the promptUSD record component
      completionUSD - the value for the completionUSD record component
      cachedDiscountUSD - the value for the cachedDiscountUSD record component
      reasoningUSD - the value for the reasoningUSD record component
      totalUSD - the value for the totalUSD record component
      pricingTableVersion - the value for the pricingTableVersion record component
  • Method Details

    • zero

      public static CostEstimate zero(String pricingTableVersion)
      Convenience: zero-cost estimate — useful for failed calls or local models.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • promptUSD

      public BigDecimal promptUSD()
      Returns the value of the promptUSD record component.
      Returns:
      the value of the promptUSD record component
    • completionUSD

      public BigDecimal completionUSD()
      Returns the value of the completionUSD record component.
      Returns:
      the value of the completionUSD record component
    • cachedDiscountUSD

      public BigDecimal cachedDiscountUSD()
      Returns the value of the cachedDiscountUSD record component.
      Returns:
      the value of the cachedDiscountUSD record component
    • reasoningUSD

      public BigDecimal reasoningUSD()
      Returns the value of the reasoningUSD record component.
      Returns:
      the value of the reasoningUSD record component
    • totalUSD

      public BigDecimal totalUSD()
      Returns the value of the totalUSD record component.
      Returns:
      the value of the totalUSD record component
    • pricingTableVersion

      public String pricingTableVersion()
      Returns the value of the pricingTableVersion record component.
      Returns:
      the value of the pricingTableVersion record component