#[non_exhaustive]pub struct Usage {
pub prompt_tokens: u32,
pub completion_tokens: u32,
pub cache_read_tokens: u32,
pub cache_creation_tokens: u32,
}Expand description
Token usage report.
Marked #[non_exhaustive] — future field additions are
additive (no SemVer-major bump required). Code outside klieo-core
that constructs a Usage must use Usage::new instead of
a struct literal; pattern matching must use the .. rest pattern.
In-crate construction is unaffected.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.prompt_tokens: u32Prompt tokens. For providers with prompt caching (e.g. Anthropic) this
is the uncached prompt count; cached tokens are reported separately
in Usage::cache_read_tokens / Usage::cache_creation_tokens.
completion_tokens: u32Completion tokens. Includes reasoning/thinking tokens where the provider
bills them as output (e.g. Gemini thoughtsTokenCount).
cache_read_tokens: u32Prompt tokens served from the provider’s cache. Billed at a reduced tier
(Anthropic ~0.1x the input rate); 0 when caching is absent or unused.
#[serde(default)] keeps pre-cache Usage JSON deserializable.
cache_creation_tokens: u32Prompt tokens written to the provider’s cache. Billed at a premium tier (Anthropic ~1.25x the input rate); 0 when caching is absent or unused.
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn new(prompt_tokens: u32, completion_tokens: u32) -> Self
pub fn new(prompt_tokens: u32, completion_tokens: u32) -> Self
Prefer this over struct literals outside klieo-core —
#[non_exhaustive] forbids external struct-literal construction so that
future field additions remain additive. Cache token counts default to 0;
set them with Usage::with_cache_tokens.
Sourcepub fn with_cache_tokens(
self,
cache_read_tokens: u32,
cache_creation_tokens: u32,
) -> Self
pub fn with_cache_tokens( self, cache_read_tokens: u32, cache_creation_tokens: u32, ) -> Self
Attach prompt-cache token counts (read = served from cache, creation = written to cache). Both bill at provider-specific tiers distinct from the base prompt rate, so they are tracked apart for correct cost pricing.