pub struct Usage {
pub input_tokens: u32,
pub cache_read_tokens: u32,
pub cache_write_tokens: u32,
pub output_tokens: u32,
pub reasoning_tokens: u32,
pub server_tool_calls: BTreeMap<String, u32>,
}Expand description
Canonical token usage. Axes are disjoint — billing computes cost as a sum over (axis, rate) pairs without any subtraction or clamping.
Input axes
input_tokens: uncached new input (the portion the model has to read fresh)cache_read_tokens: served from prompt cache (cheaper than base input)cache_write_tokens: written to prompt cache this turn (often more expensive than base input — Anthropic charges ~1.25× for cache writes)
Output axes
output_tokens: regular completion tokens, excluding reasoningreasoning_tokens: thinking/reasoning tokens (may have a separate rate)
Side-channel
server_tool_calls: per-call billing for upstream-side tools like web search. Keyed by tool name ("web_search", etc.).
Fields§
§input_tokens: u32§cache_read_tokens: u32§cache_write_tokens: u32§output_tokens: u32§reasoning_tokens: u32§server_tool_calls: BTreeMap<String, u32>Implementations§
Source§impl Usage
impl Usage
Sourcepub fn prompt_tokens(&self) -> u32
pub fn prompt_tokens(&self) -> u32
Total prompt size (cached + uncached + writes). Equivalent to OpenAI’s
prompt_tokens.
Sourcepub fn completion_tokens(&self) -> u32
pub fn completion_tokens(&self) -> u32
Total completion size including reasoning. Equivalent to OpenAI’s
completion_tokens.
Sourcepub fn total_tokens(&self) -> u32
pub fn total_tokens(&self) -> u32
Prompt plus completion — equivalent to OpenAI’s total_tokens.
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
Source§impl From<&AnthropicUsage> for Usage
impl From<&AnthropicUsage> for Usage
Source§fn from(u: &AnthropicUsage) -> Self
fn from(u: &AnthropicUsage) -> Self
Converts to this type from the input type.
Source§impl From<&GeminiUsage> for Usage
impl From<&GeminiUsage> for Usage
Source§fn from(u: &GeminiUsage) -> Self
fn from(u: &GeminiUsage) -> Self
Converts to this type from the input type.
Source§impl From<&OpenAiUsage> for Usage
impl From<&OpenAiUsage> for Usage
Source§fn from(u: &OpenAiUsage) -> Self
fn from(u: &OpenAiUsage) -> Self
Converts to this type from the input type.
Source§impl From<&Usage> for AnthropicUsage
impl From<&Usage> for AnthropicUsage
Source§impl From<&Usage> for GeminiUsage
impl From<&Usage> for GeminiUsage
Source§impl From<&Usage> for OpenAiUsage
impl From<&Usage> for OpenAiUsage
impl Eq for Usage
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