pub struct RateLimitInfo {
pub requests: Option<Window>,
pub tokens: Option<Window>,
pub retry_after: Option<Duration>,
}provider-headers only.Expand description
A normalized view of the rate-limit headers on a response.
Providers that meter requests and tokens separately (the LLM APIs) populate
both requests and tokens; single-limit
providers populate only requests. retry_after carries
a Retry-After when present.
Fields§
§requests: Option<Window>The request-count window, if the response carried one.
tokens: Option<Window>The token window, if the response carried one (LLM providers).
retry_after: Option<Duration>The Retry-After delay, if present.
Implementations§
Source§impl RateLimitInfo
impl RateLimitInfo
Sourcepub fn sync_requests<C: Clock + Clone>(&self, throttle: &Throttle<C>) -> u32
pub fn sync_requests<C: Clock + Clone>(&self, throttle: &Throttle<C>) -> u32
Reconciles throttle with the server’s reported requests-remaining,
draining tokens so the local available count does not exceed it.
This only ever reduces the local budget — it never adds tokens — so it corrects client/server drift without ever raising the throttle above its hard capacity. Returns the number of tokens drained.
§Examples
use throttle_net::Throttle;
use throttle_net::provider::{RateLimitInfo, Window};
let throttle = Throttle::per_second(100); // locally believes 100 are free
let info = RateLimitInfo {
requests: Some(Window { remaining: Some(10), ..Window::default() }),
..RateLimitInfo::default()
};
let drained = info.sync_requests(&throttle);
assert_eq!(drained, 90);
assert_eq!(throttle.available(), 10); // now matches the serverSourcepub fn sync_tokens<C: Clock + Clone>(&self, throttle: &Throttle<C>) -> u32
pub fn sync_tokens<C: Clock + Clone>(&self, throttle: &Throttle<C>) -> u32
Reconciles throttle with the server’s reported tokens-remaining, the same
way as sync_requests. Returns the tokens drained.
Trait Implementations§
Source§impl Clone for RateLimitInfo
impl Clone for RateLimitInfo
Source§fn clone(&self) -> RateLimitInfo
fn clone(&self) -> RateLimitInfo
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RateLimitInfo
Source§impl Debug for RateLimitInfo
impl Debug for RateLimitInfo
Source§impl Default for RateLimitInfo
impl Default for RateLimitInfo
Source§fn default() -> RateLimitInfo
fn default() -> RateLimitInfo
impl Eq for RateLimitInfo
Source§impl PartialEq for RateLimitInfo
impl PartialEq for RateLimitInfo
Source§fn eq(&self, other: &RateLimitInfo) -> bool
fn eq(&self, other: &RateLimitInfo) -> bool
self and other values to be equal, and is used by ==.