pub struct SmartRouter { /* private fields */ }Expand description
Routes incoming requests to the cheapest (or highest-quality) provider that satisfies all SLA constraints.
Implementations§
Source§impl SmartRouter
impl SmartRouter
Sourcepub fn new(pricing: Vec<ModelPricing>, health: ProviderHealthMonitor) -> Self
pub fn new(pricing: Vec<ModelPricing>, health: ProviderHealthMonitor) -> Self
Sourcepub async fn route(&self, req: &RoutingRequirements) -> Option<RoutingDecision>
pub async fn route(&self, req: &RoutingRequirements) -> Option<RoutingDecision>
Route a request, returning the best RoutingDecision or None if no
suitable provider exists after applying all filters.
§Panics
Never panics.
Sourcepub fn default_pricing() -> Vec<ModelPricing>
pub fn default_pricing() -> Vec<ModelPricing>
Return the built-in pricing table for common LLM models.
Prices are in USD per 1 million tokens as of early 2025.
§Panics
Never panics.
Sourcepub fn load_pricing_toml(&mut self, toml_str: &str) -> Result<usize, String>
pub fn load_pricing_toml(&mut self, toml_str: &str) -> Result<usize, String>
Hot-reload pricing from a TOML string.
The TOML document must contain a top-level [[model]] array, where each
entry has the fields: provider_id, model, input_per_million,
output_per_million, quality_score, typical_p95_ms.
On success, replaces the current pricing table and returns the number of models loaded. On parse failure, the existing table is not modified.
§Errors
Returns Err(String) describing the parse failure.
§Panics
Never panics.
Auto Trait Implementations§
impl !RefUnwindSafe for SmartRouter
impl !UnwindSafe for SmartRouter
impl Freeze for SmartRouter
impl Send for SmartRouter
impl Sync for SmartRouter
impl Unpin for SmartRouter
impl UnsafeUnpin for SmartRouter
Blanket Implementations§
Source§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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request