Class LlmPricing

java.lang.Object
org.mockserver.llm.cost.LlmPricing

public final class LlmPricing extends Object
Estimated cost calculation for LLM API usage.

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 (and possibly-lagging) table with the same prefix-walk semantics. There is no automated drift check between the two — keep them aligned when refreshing rates. This table currently carries newer model families that the UI table has not yet been updated with.

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).

  • Method Details

    • getPricing

      public static LlmPricing.PricingEntry getPricing(Provider provider, String model)
      Look up pricing for a provider and model, or null if 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 null if the model is unknown. Returns 0.0 for zero tokens on a known (priced) model.
    • cheapestModel

      public static LlmPricing.ModelOption cheapestModel(Provider provider)
      The cheapest model in the provider's pricing table by blended (input+output per-million) rate, or null for OLLAMA / unknown / tableless providers. Deterministic: ties resolve to the first table entry.
    • blendedPerMillion

      public static Double blendedPerMillion(Provider provider, String model)
      The blended (input+output per-million) rate for a provider/model, or null when the model is unpriced.