Skip to main content

Usage

Struct Usage 

Source
pub struct Usage {
    pub input_tokens: u64,
    pub output_tokens: u64,
    pub cache_read_input_tokens: u64,
    pub cache_creation_input_tokens: u64,
}
Expand description

Token accounting for a request/response pair.

Counts are cumulative within a single stream. A turn folds these across every provider call its tool-calling loop makes; the folded total is what polychrome_turn_prompt_tokens_total{token_kind} (polyc-agent’s per-turn prompt-cache-effectiveness counter, #1299) surfaces — this per-call struct itself is not exported to Prometheus directly.

Fields§

§input_tokens: u64

Tokens consumed by the prompt (system + messages + tools).

§output_tokens: u64

Tokens produced by the model.

§cache_read_input_tokens: u64

Prompt tokens served from the provider’s cache — the portion of input_tokens a cached stable prefix satisfied, so this is a SUBSET of input_tokens, not an addition to it. The Phase 0 exit metric (prompt-cache hit rate) is this over input_tokens. Zero when the provider reports no cache read or has no caching.

§cache_creation_input_tokens: u64

Prompt tokens the provider wrote INTO its cache on this call (a cache-creation / cache-write count), when the provider distinguishes them from a cache read. Also a subset of input_tokens. Zero when the provider reports no cache write or does not surface the count.

Implementations§

Source§

impl Usage

Source

pub const fn total_tokens(self) -> u64

Total tokens billed for this exchange (input_tokens + output_tokens).

Saturates rather than overflowing; real responses never approach u64::MAX, but the arithmetic is total so callers need no guard. The cache counts are subsets of input_tokens, so they are NOT added in.

Trait Implementations§

Source§

impl AddAssign for Usage

Source§

fn add_assign(&mut self, other: Self)

Folds other into self, field by field — every field named explicitly, never a ..Default::default() spread (which would silently leave a newly-added field un-summed instead of failing to compile when one side gains a field; see #1241/#1238). The single canonical accumulation every caller across the workspace should use instead of hand-rolling the same four-field fold at each call site.

Source§

impl Clone for Usage

Source§

fn clone(&self) -> Usage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Usage

Source§

impl Debug for Usage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Usage

Source§

fn default() -> Usage

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Usage

Source§

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 Eq for Usage

Source§

impl PartialEq for Usage

Source§

fn eq(&self, other: &Usage) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Usage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more