Expand description
Per-token price table keyed on each provider’s name()
§Model Pricing
Compile-time pricing data for the providers this crate runs, keyed on the
exact string each one’s LlmProvider::name
reports. MetricsProvider prices every
call through it; a consumer that layers operator overrides on top builds
its own lookup from lookup_pricing, cost_from_pricing and
zero_cost_for_unpriced, which are public for that purpose.
§Cache accounting
A prompt token can bill at three rates, so the pricing entry carries the
multipliers rather than a single global discount: fresh input at 1.0×, a
cache read at ModelPricing::cache_read_multiplier (Anthropic 0.10×,
OpenAI 0.50×, Gemini 0.25×), and a cache write at
ModelPricing::cache_write_multiplier — which is a premium on
Anthropic (1.25×), not a discount. Reasoning tokens bill at the output
rate and are additive to the completion count, because every provider that
reports them separately excludes them from it.
Counts arrive on TokenUsage, are carried
through TokenCounts, and are priced by calculate_cost_for.
Structs§
- Long
Prompt Rates - The rate card a model switches to when a request’s prompt is long.
- Model
Pricing - Per-model pricing rates in USD per million tokens, plus the two cache multipliers that turn a raw token count into a billed one.
- Token
Counts - The token counts a single LLM call reports, in the shape they bill.
Constants§
- DEFAULT_
CACHE_ READ_ RATE - Default fraction of the input rate at which a context-cache read bills.
- DEFAULT_
CACHE_ WRITE_ RATE - Default fraction of the input rate at which a context-cache write bills.
- NOT_
PER_ TOKEN_ METERED_ PROVIDERS - Providers whose per-token cost is genuinely $0 by design, so a $0 billed cost is correct rather than a missing-price undercount.
- PRICING_
TABLE - Compile-time pricing table:
(provider, model_prefix, pricing)
Functions§
- calculate_
cost - Calculate the cost of an LLM request using compile-time pricing.
- calculate_
cost_ for - Calculate the cost of an LLM request from a full
TokenCounts. - calculate_
cost_ with_ cache - Calculate the cost of an LLM request, breaking the prompt into cached + fresh tokens.
- cost_
from_ pricing - Compute the USD cost from a resolved
ModelPricing+ token counts. Shared by the compile-time lookup and any override path a consumer layers on top, so both sources price a call identically. - is_
not_ per_ token_ metered - True when a provider bills via flat-rate subscription or self-hosting, so a $0 per-token cost is correct rather than a missing-price undercount.
- lookup_
pricing - Look up pricing for a (provider, model) pair using prefix matching.
- pool_
family - The provider a pooled tier prices as:
claude-code#2is a second Claude account, billed like the first. Seecrate::pool. - zero_
cost_ for_ unpriced - Log the resolution of a (provider, model) pair that has no
PRICING_TABLEor override entry, at a severity matching why it is unpriced, and return the $0 cost all three paths fall back to.