#[non_exhaustive]pub struct TokenEstimate {
pub image_tokens: ImageTokens,
pub input_micro_usd_per_million: u64,
pub output_micro_usd_per_million: u64,
pub max_output_tokens: u32,
}Expand description
A token-billed backend’s preflight: how its images count, its rates, and the output cap assumed when a call sets none.
§Example
use adk_vision::{ImageTokens, TokenEstimate};
// $3 per million input tokens, $15 per million output tokens.
let sonnet = TokenEstimate::new(ImageTokens::Claude, 3_000_000, 15_000_000).with_max_output_tokens(1_024);
// One 560×280 crop (200 visual tokens), a 400-character prompt (100 tokens), 1,024 output tokens.
assert_eq!(sonnet.estimate_micro_usd(&[(560, 280)], 400, None), 900 + 15_360);
// A call that caps its own output at 100 tokens.
assert_eq!(sonnet.estimate_micro_usd(&[(560, 280)], 400, Some(100)), 900 + 1_500);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.image_tokens: ImageTokensHow the provider counts image tokens.
input_micro_usd_per_million: u64Input price in micro-USD per million tokens.
output_micro_usd_per_million: u64Output price in micro-USD per million tokens.
max_output_tokens: u32The output tokens assumed when a call sets no cap.
Implementations§
Source§impl TokenEstimate
impl TokenEstimate
Sourcepub const CHARS_PER_TOKEN: u64 = 4
pub const CHARS_PER_TOKEN: u64 = 4
Characters per prompt token assumed for the estimate.
Sourcepub fn new(
image_tokens: ImageTokens,
input_micro_usd_per_million: u64,
output_micro_usd_per_million: u64,
) -> Self
pub fn new( image_tokens: ImageTokens, input_micro_usd_per_million: u64, output_micro_usd_per_million: u64, ) -> Self
An estimate at these rates, assuming 4,096 output tokens when a call sets no cap.
Sourcepub fn with_max_output_tokens(self, tokens: u32) -> Self
pub fn with_max_output_tokens(self, tokens: u32) -> Self
Sets the output tokens assumed when a call sets no cap.
Trait Implementations§
Source§impl Clone for TokenEstimate
impl Clone for TokenEstimate
impl Copy for TokenEstimate
Source§impl Debug for TokenEstimate
impl Debug for TokenEstimate
Source§impl<'de> Deserialize<'de> for TokenEstimate
impl<'de> Deserialize<'de> for TokenEstimate
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for TokenEstimate
Source§impl PartialEq for TokenEstimate
impl PartialEq for TokenEstimate
Source§impl Serialize for TokenEstimate
impl Serialize for TokenEstimate
impl StructuralPartialEq for TokenEstimate
Auto Trait Implementations§
impl Forget for TokenEstimate
impl Freeze for TokenEstimate
impl Move for TokenEstimate
impl RefUnwindSafe for TokenEstimate
impl Send for TokenEstimate
impl Sync for TokenEstimate
impl Unpin for TokenEstimate
impl UnsafeUnpin for TokenEstimate
impl UnwindSafe for TokenEstimate
Blanket Implementations§
impl<T> Boilerplate for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> Downcast for T
impl<T> Downcast for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.