CostEstimator
org.llm4s.llmconnect.provider.CostEstimator
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 ModelRegistry 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
- Preserves precision of micro-cost values
- 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(0.0015) for gpt-4o pricing
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
CostEstimator.type
Members list
In this article