#[non_exhaustive]pub struct CostPreview {
pub model: ModelId,
pub input_tokens: u32,
pub max_output_tokens: u32,
pub input_cost_usd: f64,
pub max_output_cost_usd: f64,
pub max_total_usd: f64,
}Available on crate features
async and pricing only.Expand description
Pre-flight cost estimate for a request.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.model: ModelIdModel the estimate was computed for.
input_tokens: u32Server-counted input tokens (from /v1/messages/count_tokens).
max_output_tokens: u32Output upper bound, taken from request.max_tokens.
input_cost_usd: f64USD cost of the input tokens alone.
max_output_cost_usd: f64USD cost if the model emits exactly max_output_tokens output tokens.
max_total_usd: f64input_cost_usd + max_output_cost_usd. The largest amount this
request could cost in vanilla usage (excludes cache/server-tool
charges since those are runtime-determined).
Implementations§
Source§impl CostPreview
impl CostPreview
Sourcepub fn cost_for(&self, output_tokens: u32, pricing: &PricingTable) -> f64
pub fn cost_for(&self, output_tokens: u32, pricing: &PricingTable) -> f64
USD cost if the model produces exactly output_tokens tokens. Useful
for plotting expected cost against an empirical output-size estimate.
Trait Implementations§
Source§impl Clone for CostPreview
impl Clone for CostPreview
Source§fn clone(&self) -> CostPreview
fn clone(&self) -> CostPreview
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CostPreview
impl Debug for CostPreview
Source§impl PartialEq for CostPreview
impl PartialEq for CostPreview
impl StructuralPartialEq for CostPreview
Auto Trait Implementations§
impl Freeze for CostPreview
impl RefUnwindSafe for CostPreview
impl Send for CostPreview
impl Sync for CostPreview
impl Unpin for CostPreview
impl UnsafeUnpin for CostPreview
impl UnwindSafe for CostPreview
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.