#[non_exhaustive]pub struct Cost {
pub input: Option<f64>,
pub output: Option<f64>,
pub cache_read: Option<f64>,
pub cache_write: Option<f64>,
pub total: f64,
}Expand description
What one or more turns cost, in USD. total is what was charged.
A part is None when its source does not give it: a provider that
reports only a total leaves every part None, and one that reports
input and output leaves the cache parts None. A cost computed from
the catalog (Pricing::cost) has every
part Some, and it prices a cache rate the catalog does not list at the
input rate, so a Some cache part may be that estimate rather than a
listed price. A part is never filled with a placeholder 0.0. Summing
costs keeps a part only when every side has it. A None part is left
out when serialized, and an absent one reads back as None.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.input: Option<f64>Uncached input tokens.
output: Option<f64>Output tokens, reasoning included.
cache_read: Option<f64>Input tokens read from a cache.
cache_write: Option<f64>Input tokens written to a cache.
total: f64The whole charge.
Implementations§
Source§impl Cost
impl Cost
Sourcepub fn from_parts(
input: f64,
output: f64,
cache_read: f64,
cache_write: f64,
) -> Cost
pub fn from_parts( input: f64, output: f64, cache_read: f64, cache_write: f64, ) -> Cost
A cost split into its parts, each known; total is their sum.
Sourcepub fn from_total(total: f64) -> Cost
pub fn from_total(total: f64) -> Cost
A cost known only as its total; every part is None.
Sourcepub fn input(self, input: impl Into<Option<f64>>) -> Cost
pub fn input(self, input: impl Into<Option<f64>>) -> Cost
Set, or with None clear, Self::input.
total is left as it is.
Sourcepub fn output(self, output: impl Into<Option<f64>>) -> Cost
pub fn output(self, output: impl Into<Option<f64>>) -> Cost
Set, or with None clear, Self::output.
total is left as it is.
Sourcepub fn cache_read(self, cache_read: impl Into<Option<f64>>) -> Cost
pub fn cache_read(self, cache_read: impl Into<Option<f64>>) -> Cost
Set, or with None clear, Self::cache_read.
total is left as it is.
Sourcepub fn cache_write(self, cache_write: impl Into<Option<f64>>) -> Cost
pub fn cache_write(self, cache_write: impl Into<Option<f64>>) -> Cost
Set, or with None clear, Self::cache_write.
total is left as it is.
Trait Implementations§
Source§impl Add for Cost
total always sums. Each part sums only when both sides know it, and is
None otherwise, so a summed part never understates what it covers.
impl Add for Cost
total always sums. Each part sums only when both sides know it, and is
None otherwise, so a summed part never understates what it covers.