pub struct ModelPricing {
pub input_per_million: f64,
pub output_per_million: f64,
pub cache_read_multiplier: f64,
pub cache_write_multiplier: f64,
pub long_prompt: Option<LongPromptRates>,
}Expand description
Per-model pricing rates in USD per million tokens, plus the two cache multipliers that turn a raw token count into a billed one.
Cache economics are per-provider, not universal: Anthropic reads at
0.10× and charges a premium to write at 1.25×, OpenAI reads at 0.50×
and does not bill writes separately, Gemini reads at 0.25×. A single
flat discount mispriced all three, so the rates travel with the model.
Fields§
§input_per_million: f64USD per 1 million input (prompt) tokens
output_per_million: f64USD per 1 million output (completion) tokens
cache_read_multiplier: f64Fraction of input_per_million at which cache-read tokens bill.
cache_write_multiplier: f64Fraction of input_per_million at which cache-write tokens bill.
long_prompt: Option<LongPromptRates>A second rate card for long prompts, when the model has one: a request whose gross prompt exceeds its threshold bills every token — input, cache and output — at the long-prompt rates.
Implementations§
Source§impl ModelPricing
impl ModelPricing
Sourcepub const fn new(input_per_million: f64, output_per_million: f64) -> Self
pub const fn new(input_per_million: f64, output_per_million: f64) -> Self
Rates for a model that uses the default cache multipliers.
Sourcepub const fn with_long_prompt_rates(
self,
above_prompt_tokens: i64,
input_per_million: f64,
output_per_million: f64,
) -> Self
pub const fn with_long_prompt_rates( self, above_prompt_tokens: i64, input_per_million: f64, output_per_million: f64, ) -> Self
Bill a request whose gross prompt exceeds above_prompt_tokens at
the given input / output rates instead of the base card.
Sourcepub fn rates_for_prompt(&self, prompt_tokens: i64) -> (f64, f64)
pub fn rates_for_prompt(&self, prompt_tokens: i64) -> (f64, f64)
The (input, output) rates per million tokens for a request with a gross prompt
of prompt_tokens: the long-prompt card above its threshold, the base
card otherwise.
Sourcepub const fn with_cache_rates(self, read: f64, write: f64) -> Self
pub const fn with_cache_rates(self, read: f64, write: f64) -> Self
Override the cache read/write multipliers for a provider that prices
them differently — Anthropic at (0.10, 1.25), OpenAI at (0.50, 1.0).