pub struct BudgetGuard { /* private fields */ }Expand description
The resolved budget for one request: a live guard over the ledger.
Implementations§
Source§impl BudgetGuard
impl BudgetGuard
Sourcepub fn check(&self, now_s: u64) -> BudgetVerdict
pub fn check(&self, now_s: u64) -> BudgetVerdict
Pre-check BEFORE any provider contact: rejected when either
window is already exhausted (both windows are checked
independently — the done-when requirement). Retry-After is
the time to the denying window’s boundary (the later wall when
both are exhausted), and the verdict’s kind is the window that
set it.
Sourcepub fn check_with_estimate(
&self,
now_s: u64,
estimated_tokens: u64,
) -> BudgetVerdict
pub fn check_with_estimate( &self, now_s: u64, estimated_tokens: u64, ) -> BudgetVerdict
Pre-check WITH a local token estimate (PERF-01): like
check but also rejects when the estimated
total tokens for this request would push the minute window OVER
its limit. estimated_tokens is the local estimate of the
request’s total token cost (prompt estimate + requested
max_tokens); the check is spent + estimated_tokens > limit
(strictly greater — a request that lands exactly on the limit
is allowed, matching the original check-then-spend contract
where a holder at the limit can complete one more request).
The estimate is CONSERVATIVE (overcounts), so a rejection here
is the honest boundary: the provider call is skipped, the
client sees 429 ai_budget_exceeded, and the actual spend is
never recorded (no provider contact). The cost window is NOT
estimated (cost depends on the provider’s pricing table and the
actual token mix, not a pre-call estimate); only the token
window benefits from the estimate.
Sourcepub fn spend(&self, now_s: u64, usage: Usage, cost_micros: u64) -> bool
pub fn spend(&self, now_s: u64, usage: Usage, cost_micros: u64) -> bool
Record the provider-reported usage after the call. Returns whether THIS spend crossed the token window (the mid-stream cutoff signal; the spend is recorded either way).
Sourcepub fn cutoff_frame(rid: &str) -> String
pub fn cutoff_frame(rid: &str) -> String
The SSE event frame for a mid-stream budget cutoff (the documented over-budget event; DW-077’s terminator follows).
Auto Trait Implementations§
impl Freeze for BudgetGuard
impl RefUnwindSafe for BudgetGuard
impl Send for BudgetGuard
impl Sync for BudgetGuard
impl Unpin for BudgetGuard
impl UnwindSafe for BudgetGuard
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§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
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more