pub struct Usage {
pub completion_tokens: usize,
pub prompt_tokens: usize,
pub total_tokens: usize,
pub service_tier: Option<String>,
pub prompt_audio_seconds: Option<u64>,
pub num_cached_tokens: Option<u64>,
pub prompt_tokens_details: Option<PromptTokensDetails>,
}Expand description
Token usage returned by Mistral’s chat completions and embeddings endpoints.
See https://docs.mistral.ai/api/ (UsageInfo schema). The three counts are
always present; the remaining fields are populated by Mistral on a best-effort
basis (e.g. cached-token information appears once a prompt is large enough to
be cached).
Fields§
§completion_tokens: usize§prompt_tokens: usize§total_tokens: usize§service_tier: Option<String>Capacity tier that served the request, when Mistral reports it.
Although the generated UsageInfo reference currently omits this
field, the live chat-completions wire includes values such as
"standard" in both blocking responses and terminal stream chunks.
Keeping it here prevents the provider-native raw_completion and
raw_stream surfaces from silently discarding that wire metadata.
prompt_audio_seconds: Option<u64>Duration in seconds of audio tokens in the prompt (audio-input models only).
num_cached_tokens: Option<u64>Total cached prompt tokens reported at the top level. Some Mistral
responses populate this in addition to (or instead of)
prompt_tokens_details.cached_tokens.
prompt_tokens_details: Option<PromptTokensDetails>In-depth breakdown of prompt token usage (currently only cached tokens).
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn cached_tokens(&self) -> u64
pub fn cached_tokens(&self) -> u64
Returns the number of cached prompt tokens, preferring the structured
prompt_tokens_details.cached_tokens field and falling back to the
top-level num_cached_tokens. Returns 0 when neither is present.
Sourcepub fn audio_tokens(&self) -> u64
pub fn audio_tokens(&self) -> u64
Tokens charged for audio in the prompt. 0 for every non-audio turn.
Sourcepub fn input_tokens(&self) -> u64
pub fn input_tokens(&self) -> u64
Every token charged against the prompt.
Mistral reports audio outside prompt_tokens: a Voxtral turn answering
a 375-audio-token clip reports prompt_tokens: 6, audio_tokens: 375,
completion_tokens: 2 and total_tokens: 383. Counting only
prompt_tokens as input leaves input + output short of total by the
whole audio payload.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Usage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Usage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Usage
impl Serialize for Usage
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Usage
impl RefUnwindSafe for Usage
impl Send for Usage
impl Sync for Usage
impl Unpin for Usage
impl UnsafeUnpin for Usage
impl UnwindSafe for Usage
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
impl<T> DebuggableStorage for T
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> 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> IntoToolOutput for Twhere
T: Serialize + 'static,
impl<T> IntoToolOutput for Twhere
T: Serialize + 'static,
Source§fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>
fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.