pub struct RouterBudget { /* private fields */ }Expand description
A circuit breaker over cumulative spend and/or token usage.
Construct with one of the constructors, wrap in an Arc, and attach via
super::RouterLLM::with_budget. Cloning is not supported; share by
Arc so every call of one run observes the same totals.
Implementations§
Source§impl RouterBudget
impl RouterBudget
Sourcepub fn with_cost_limit(max_cost_usd: f64) -> Self
pub fn with_cost_limit(max_cost_usd: f64) -> Self
Only a USD spend cap.
Sourcepub fn with_token_limit(max_tokens: u64) -> Self
pub fn with_token_limit(max_tokens: u64) -> Self
Only a cumulative token cap.
Sourcepub fn with_cost_and_token_limits(
max_cost_usd: f64,
max_tokens: u64,
) -> Arc<Self> ⓘ
pub fn with_cost_and_token_limits( max_cost_usd: f64, max_tokens: u64, ) -> Arc<Self> ⓘ
Both a USD cap and a token cap; either one tripping skips the slot.
Sourcepub fn max_cost_usd(&self) -> Option<f64>
pub fn max_cost_usd(&self) -> Option<f64>
Configured USD cap, if any.
Sourcepub fn max_tokens(&self) -> Option<u64>
pub fn max_tokens(&self) -> Option<u64>
Configured token cap, if any.
Sourcepub fn is_tripped(&self) -> bool
pub fn is_tripped(&self) -> bool
Whether either cap is already crossed.
Sourcepub fn precheck(
&self,
projected_cost_usd: f64,
projected_tokens: u64,
) -> Result<(), BudgetExceeded>
pub fn precheck( &self, projected_cost_usd: f64, projected_tokens: u64, ) -> Result<(), BudgetExceeded>
Projects one pending call and returns the dimension that would be exceeded, if any.
projected_cost_usd is the prompt priced against the slot’s price
(0.0 for free/unpriced slots); projected_tokens is the prompt-token
estimate. A projected zero-cost call always passes the cost
dimension even while the breaker is tripped — that is what lets free
fallbacks keep serving. The token dimension is price-agnostic.