pub struct ModelRateLimit { /* private fields */ }Expand description
Per-model rate / concurrency limits attached to one router slot.
Construct with ModelRateLimit::per_minute (or
ModelRateLimit::per_second) and tighten the optional dimensions with
the with_* builders. Pass to
RouterLLM::with_model_rate_limited
or RouterLLM::with_last_rate_limit.
Implementations§
Source§impl ModelRateLimit
impl ModelRateLimit
Sourcepub fn per_minute(requests_per_minute: usize) -> Self
pub fn per_minute(requests_per_minute: usize) -> Self
At most requests_per_minute admitted per 60-second window, unlimited
concurrency, unbounded queue, 60-second wait timeout.
Sourcepub fn per_second(requests_per_second: usize) -> Self
pub fn per_second(requests_per_second: usize) -> Self
At most requests_per_second admitted per one-second window.
Sourcepub fn with_window(self, window: Duration) -> Self
pub fn with_window(self, window: Duration) -> Self
Overrides the rate window length (e.g. a provider quota stated per day).
The wait timeout is intentionally left untouched: a queued caller may
legitimately wait several windows deep, so configure
ModelRateLimit::with_wait_timeout separately when shortening.
Sourcepub fn with_max_concurrent(self, max_concurrent: usize) -> Self
pub fn with_max_concurrent(self, max_concurrent: usize) -> Self
Bounds in-flight calls. The slot stays occupied until the whole
response (including a streamed body) has finished. 0 (the default)
disables the concurrency dimension.
Sourcepub fn with_max_queue(self, max_queue: usize) -> Self
pub fn with_max_queue(self, max_queue: usize) -> Self
Bounds how many callers may wait for admission; 0 (the default)
means an unbounded FIFO queue. A full queue rejects immediately with
RouterError::RateLimited so the
router can fall through to a fallback model without delay.
Sourcepub fn with_wait_timeout(self, wait_timeout: Duration) -> Self
pub fn with_wait_timeout(self, wait_timeout: Duration) -> Self
Caps how long one caller waits before the router gives up on this slot and tries the next model. Defaults to one rate window.
Sourcepub fn requests_per_window(&self) -> usize
pub fn requests_per_window(&self) -> usize
Configured requests-per-window.
Sourcepub fn max_concurrent(&self) -> usize
pub fn max_concurrent(&self) -> usize
Configured concurrency cap (0 = unlimited).
Sourcepub fn wait_timeout(&self) -> Duration
pub fn wait_timeout(&self) -> Duration
Configured admission wait timeout.
Trait Implementations§
Source§impl Clone for ModelRateLimit
impl Clone for ModelRateLimit
Source§fn clone(&self) -> ModelRateLimit
fn clone(&self) -> ModelRateLimit
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more