Class LlmPricing
A pure lookup over a pricing table keyed on (provider, model) with
input/output rates in USD per million tokens. Returns null for an
unknown model so callers can distinguish "free/known-zero" from "unpriceable".
Companion dashboard pricing table
mockserver-ui/src/lib/llmPricing.ts maintains a parallel table with
the same prefix-walk semantics, and is kept in sync with this table. A
UI-side drift guard (mockserver-ui/src/__tests__/llmPricing.test.ts)
snapshots the expected prefixes and rates and fails if the dashboard table
drifts from them, so when refreshing rates update both tables together and
update that test's canonical snapshot to match.
Pricing source / freshness: rates are public provider list prices captured 2026-06 (newer families) / 2025-Q4 (original entries). They WILL drift — treat any total as an estimate, not an invoice. Sources: Anthropic (anthropic.com/pricing), OpenAI (openai.com/api/pricing), Gemini (ai.google.dev/pricing).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe cheapest model in a provider's pricing table — its prefix label and blended (input+output per-million) rate.static final classInput/output list price in USD per million tokens. -
Method Summary
Modifier and TypeMethodDescriptionstatic DoubleblendedPerMillion(Provider provider, String model) The blended (input+output per-million) rate for a provider/model, ornullwhen the model is unpriced.static LlmPricing.ModelOptioncheapestModel(Provider provider) The cheapest model in the provider's pricing table by blended (input+output per-million) rate, ornullfor OLLAMA / unknown / tableless providers.static DoubleestimateCostUsd(Provider provider, String model, long inputTokens, long outputTokens) Estimate the cost in USD for a provider, model, and token counts.static LlmPricing.PricingEntrygetPricing(Provider provider, String model) Look up pricing for a provider and model, ornullif unrecognised.static booleanisApproximateRate(Provider provider, String model) True when the provider/model resolves to an admitted-placeholder / approximate rate (e.g. gpt-5*), so any cost derived from it must be flagged as an estimate rather than fact.
-
Method Details
-
getPricing
Look up pricing for a provider and model, ornullif unrecognised. -
estimateCostUsd
public static Double estimateCostUsd(Provider provider, String model, long inputTokens, long outputTokens) Estimate the cost in USD for a provider, model, and token counts.- Returns:
- the estimated cost in USD, or
nullif the model is unknown. Returns0.0for zero tokens on a known (priced) model.
-
isApproximateRate
True when the provider/model resolves to an admitted-placeholder / approximate rate (e.g. gpt-5*), so any cost derived from it must be flagged as an estimate rather than fact. False for an unpriced model (no entry) or a verified list price. -
cheapestModel
The cheapest model in the provider's pricing table by blended (input+output per-million) rate, ornullfor OLLAMA / unknown / tableless providers. Deterministic: ties resolve to the first table entry. -
blendedPerMillion
The blended (input+output per-million) rate for a provider/model, ornullwhen the model is unpriced.
-