pub struct Usage {
pub prompt_tokens: u32,
pub completion_tokens: u32,
pub total_tokens: u32,
pub cost_usd: Option<f64>,
pub prompt_tokens_details: Option<PromptTokensDetails>,
pub cache_creation_tokens: Option<u32>,
}Expand description
Token accounting echoed on every response. cost_usd is an llmleaf addition and is
absent when the model has no known price.
Fields§
§prompt_tokens: u32§completion_tokens: u32§total_tokens: u32§cost_usd: Option<f64>§prompt_tokens_details: Option<PromptTokensDetails>Prompt-cache hit accounting (OpenAI usage.prompt_tokens_details). Absent when the upstream
reported no caching; Usage::cached_tokens flattens it to a plain count.
cache_creation_tokens: Option<u32>Input tokens written to the provider’s prompt cache this request — a cache write (creation). An llmleaf extension (Anthropic reports it; OpenAI/OpenRouter do not); absent when there were none.
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn cached_tokens(&self) -> u32
pub fn cached_tokens(&self) -> u32
Prompt tokens served from the provider’s cache this request — a cache read (hit). 0 when
the upstream reported no caching.
Sourcepub fn cache_writes(&self) -> u32
pub fn cache_writes(&self) -> u32
Input tokens written to the provider’s cache this request — a cache write (creation). 0
when there were none (or the provider does not report writes).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
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 StructuralPartialEq for Usage
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
Mutably borrows from an owned value. Read more