pub struct ModelPricing {
pub input_cost_per_token: f64,
pub output_cost_per_token: f64,
pub cache_read_input_token_cost: f64,
pub cache_creation_input_token_cost: f64,
pub cache_creation_input_token_cost_above_1hr: f64,
pub output_cost_per_reasoning_token: f64,
pub web_search_cost_per_query: f64,
pub tiers: Vec<ThresholdTier>,
pub ranges: Option<Vec<TierRange>>,
}Expand description
Pricing data for a single AI model in USD per token.
Supports three strategies, checked in this order by calculate_cost:
- Range-based (
rangesisSome):input_tokensselects aTierRangeand its prices are applied standalone. Used by Qwen / doubao families. - Threshold-based (
tiersis non-empty): the highestThresholdTierwhosethreshold_tokensis exceeded by total input context wins; all token types switch to that tier’s prices. Used by Claude Sonnet 4.x, Gemini 2.5 Pro, Gemini 1.5 (128k), GPT-5.x (272k), etc. - Flat (neither set): base prices apply to every request.
This struct is only ever held in memory — tiers / ranges are derived
from the raw *_above_Nk_tokens / tiered_pricing keys of LiteLLM by
parse_litellm_entry. Cache files store the raw LiteLLM cost fields
verbatim (see filter_cost_fields); reloading the cache runs
them back through parse_litellm_entry so the derived structures are
reconstructed freshly on every launch.
Fields§
§input_cost_per_token: f64Base input price in USD per token.
output_cost_per_token: f64Base output price in USD per token.
cache_read_input_token_cost: f64Base cache-read price in USD per token.
cache_creation_input_token_cost: f64Base cache-write (5-minute TTL) price in USD per token.
cache_creation_input_token_cost_above_1hr: f64Price per token for cache writes using Anthropic’s extended (1 hour) TTL.
0.0 means the model doesn’t support 1hr cached writes — callers fall
back to cache_creation_input_token_cost (5-minute TTL price).
output_cost_per_reasoning_token: f64Price for reasoning / thinking tokens emitted as part of the assistant
response but billed separately from regular output tokens. Populated
by Gemini 2.5 flash / flash-lite (thoughts_tokens), perplexity
sonar-deep-research, and some qwen-turbo entries. 0.0 means the
model doesn’t split reasoning from output — callers fall back to
output_cost_per_token.
web_search_cost_per_query: f64Price in USD for one server-side web-search request
(server_tool_use.web_search_requests), billed per query rather than
per token. Derived by parse_litellm_entry from LiteLLM’s nested
search_context_cost_per_query object (Anthropic charges a flat
$0.01 across its low/medium/high sizes). 0.0 means the model
publishes no web-search price.
tiers: Vec<ThresholdTier>Threshold-based tiers, sorted ascending by threshold_tokens.
ranges: Option<Vec<TierRange>>Range-based pricing (mutually exclusive with tiers in practice).
Trait Implementations§
Source§impl Clone for ModelPricing
impl Clone for ModelPricing
Source§fn clone(&self) -> ModelPricing
fn clone(&self) -> ModelPricing
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModelPricing
impl Debug for ModelPricing
Source§impl Default for ModelPricing
impl Default for ModelPricing
Source§fn default() -> ModelPricing
fn default() -> ModelPricing
Source§impl<'de> Deserialize<'de> for ModelPricing
impl<'de> Deserialize<'de> for ModelPricing
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ModelPricing
impl RefUnwindSafe for ModelPricing
impl Send for ModelPricing
impl Sync for ModelPricing
impl Unpin for ModelPricing
impl UnsafeUnpin for ModelPricing
impl UnwindSafe for ModelPricing
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more