Skip to main content

UsageSnapshot

Struct UsageSnapshot 

Source
pub struct UsageSnapshot {
    pub source: UsageSourceKind,
    pub fetched_at: SystemTime,
    pub five_hour: Option<UsageWindow>,
    pub seven_day: Option<UsageWindow>,
    pub seven_day_opus: Option<UsageWindow>,
    pub seven_day_sonnet: Option<UsageWindow>,
    pub extra_usage: Option<ExtraUsage>,
    pub spend: Option<ApiSpend>,
    pub balance: Option<f64>,
}
Expand description

Snapshot of the user’s Anthropic plan utilization at a point in time. Composed by the forge-gateway backends and rendered by a view.

Fields§

§source: UsageSourceKind§fetched_at: SystemTime§five_hour: Option<UsageWindow>§seven_day: Option<UsageWindow>§seven_day_opus: Option<UsageWindow>§seven_day_sonnet: Option<UsageWindow>§extra_usage: Option<ExtraUsage>§spend: Option<ApiSpend>

Per-key spend for an API-billed account. None for every window-billed source, and for every row written before this field existed - serde decodes a missing key on an Option to None, which is what keeps the cached rows readable.

§balance: Option<f64>

The OpenRouter account’s remaining credit pool, in USD: total_credits - total_usage from /v1/credits. Account-wide - every key on the account draws on the same pool - unlike the per-key figures in ApiSpend. None when the credits fetch failed, when the 200 carried no data envelope, and for every cached row written before this field existed, decoded as absent like spend above.

Implementations§

Source§

impl UsageSnapshot

Source

pub fn five_hour_util(&self) -> Option<f64>

None when the snapshot carries no five-hour window, which is a documented steady state on the lenient mapper rather than a zero.

Source

pub fn seven_day_util(&self) -> Option<f64>

Binding 7-day utilisation: max across the three 7-day windows (seven_day, seven_day_opus, seven_day_sonnet). Whichever is most-used is the binding constraint for “is this account 7-day rate-limited.”

None when all three are absent, which a 200 carrying only the session window produces.

Source

pub fn binding_reset_at(&self) -> Option<SystemTime>

When a rate-limited account unlocks: the latest resets_at among windows currently at-or-over the cap (per is_currently_limited). None when no window is currently capped, so a reset ETA is shown only on rate-limited rows.

Source

pub fn same_usage(&self, other: &UsageSnapshot) -> bool

Whether two snapshots say the same thing, fetched_at aside.

Derived PartialEq cannot answer this: fetched_at moves on every probe, so two successful polls that found an unchanged pool compare unequal and every poll reads as news. The field says when a reading was taken, not what it says, and it is the only one excluded here - a new usage field belongs in the comparison below.

Trait Implementations§

Source§

impl Clone for UsageSnapshot

Source§

fn clone(&self) -> UsageSnapshot

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 Debug for UsageSnapshot

Source§

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

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

impl<'de> Deserialize<'de> for UsageSnapshot

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<UsageSnapshot, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for UsageSnapshot

Source§

fn eq(&self, other: &UsageSnapshot) -> 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 UsageSnapshot

Source§

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

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

impl StructuralPartialEq for UsageSnapshot

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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