CostEstimator
org.llm4s.llmconnect.provider.CostEstimator
@Stable
object CostEstimator
Centralized cost estimation for LLM completions.
This provides a single source of truth for estimating completion costs based on token usage and model pricing information. It integrates with the ModelRegistryService to look up pricing data and applies it to usage statistics.
The estimator:
- Uses existing ModelPricing logic (no duplication)
- Returns None if pricing is unavailable
- Computes in
BigDecimal, so a micro-cost is exact and sums of them do not drift - Works uniformly across all providers
Example usage:
val usage = TokenUsage(promptTokens = 100, completionTokens = 50, totalTokens = 150)
val cost = CostEstimator.estimate("gpt-4o", usage)
// cost: Some(BigDecimal("0.0015")) for gpt-4o pricing
Attributes
- Source
- CostEstimator.scala
- Graph
-
- Supertypes
- Self type
-
CostEstimator.type
Members list
In this article
