pub struct ProviderPreferences {
pub order: Option<Vec<String>>,
pub only: Option<Vec<String>>,
pub ignore: Option<Vec<String>>,
pub allow_fallbacks: Option<bool>,
pub require_parameters: Option<bool>,
pub data_collection: Option<DataCollection>,
pub zdr: Option<bool>,
pub sort: Option<ProviderSort>,
pub preferred_min_throughput: Option<ThroughputThreshold>,
pub preferred_max_latency: Option<LatencyThreshold>,
pub max_price: Option<MaxPrice>,
pub quantizations: Option<Vec<Quantization>>,
}Expand description
Provider preferences for OpenRouter routing.
This struct allows you to control which providers are used and how they are prioritized when making requests through OpenRouter.
See: https://openrouter.ai/docs/guides/routing/provider-selection
§Example
use rig::providers::openrouter::{ProviderPreferences, ProviderSortStrategy, Quantization};
// Create preferences for zero data retention providers, sorted by throughput
let prefs = ProviderPreferences::new()
.sort(ProviderSortStrategy::Throughput)
.zdr(true)
.quantizations([Quantization::Int8])
.only(["anthropic", "openai"]);Fields§
§order: Option<Vec<String>>Try these provider slugs in the given order first.
If allow_fallbacks: true, OpenRouter may try other providers after this list is exhausted.
only: Option<Vec<String>>Hard allowlist. Only these provider slugs are eligible.
ignore: Option<Vec<String>>Blocklist. These provider slugs are never used.
allow_fallbacks: Option<bool>If false, the router will not use any providers outside what your constraints permit.
Default is true.
require_parameters: Option<bool>If true, only route to providers that support all parameters in your request.
Default is false.
data_collection: Option<DataCollection>Data collection policy. If DataCollection::Deny, restrict routing to providers
that do not store user data non-transiently. Default is DataCollection::Allow.
zdr: Option<bool>If true, restrict routing to Zero Data Retention endpoints only.
sort: Option<ProviderSort>Sorting strategy. Affects ordering, not strict exclusion. If set, default load balancing is disabled.
preferred_min_throughput: Option<ThroughputThreshold>Throughput threshold. Endpoints not meeting the threshold are deprioritized.
preferred_max_latency: Option<LatencyThreshold>Latency threshold. Endpoints not meeting the threshold are deprioritized.
max_price: Option<MaxPrice>Hard price ceiling. If no provider is at or under, the request fails.
quantizations: Option<Vec<Quantization>>Restrict routing to providers serving specific quantization levels.
Implementations§
Source§impl ProviderPreferences
impl ProviderPreferences
Sourcepub fn order(
self,
providers: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn order( self, providers: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Try these provider slugs in the given order first.
If allow_fallbacks is true (default), OpenRouter may try other providers
after this list is exhausted.
§Example
use rig::providers::openrouter::ProviderPreferences;
let prefs = ProviderPreferences::new()
.order(["anthropic", "openai"]);Sourcepub fn only(
self,
providers: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn only( self, providers: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Hard allowlist. Only these provider slugs are eligible.
§Example
use rig::providers::openrouter::ProviderPreferences;
let prefs = ProviderPreferences::new()
.only(["azure", "together"])
.allow_fallbacks(false);Sourcepub fn ignore(
self,
providers: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn ignore( self, providers: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Blocklist. These provider slugs are never used.
§Example
use rig::providers::openrouter::ProviderPreferences;
let prefs = ProviderPreferences::new()
.ignore(["deepinfra"]);Sourcepub fn allow_fallbacks(self, allow: bool) -> Self
pub fn allow_fallbacks(self, allow: bool) -> Self
Control whether fallbacks are allowed.
If false, the router will not use any providers outside what your constraints permit.
Default is true.
Sourcepub fn require_parameters(self, require: bool) -> Self
pub fn require_parameters(self, require: bool) -> Self
If true, only route to providers that support all parameters in your request.
Default is false, meaning providers may ignore unsupported parameters.
Sourcepub fn data_collection(self, policy: DataCollection) -> Self
pub fn data_collection(self, policy: DataCollection) -> Self
Set data collection policy.
If Deny, restrict routing to providers that do not store user data non-transiently.
Sourcepub fn zdr(self, enable: bool) -> Self
pub fn zdr(self, enable: bool) -> Self
If true, restrict routing to Zero Data Retention endpoints only.
§Example
use rig::providers::openrouter::ProviderPreferences;
let prefs = ProviderPreferences::new()
.zdr(true);Sourcepub fn sort(self, sort: impl Into<ProviderSort>) -> Self
pub fn sort(self, sort: impl Into<ProviderSort>) -> Self
Set the sorting strategy for providers.
If set, default load balancing is disabled and providers are tried deterministically in the resulting order.
§Example
use rig::providers::openrouter::{ProviderPreferences, ProviderSortStrategy};
let prefs = ProviderPreferences::new()
.sort(ProviderSortStrategy::Latency);Sourcepub fn preferred_min_throughput(self, threshold: ThroughputThreshold) -> Self
pub fn preferred_min_throughput(self, threshold: ThroughputThreshold) -> Self
Set preferred minimum throughput threshold.
Endpoints not meeting the threshold are deprioritized (moved later), not excluded.
§Example
use rig::providers::openrouter::{ProviderPreferences, ThroughputThreshold, PercentileThresholds};
// Simple threshold
let prefs = ProviderPreferences::new()
.preferred_min_throughput(ThroughputThreshold::Simple(50.0));
// Percentile threshold
let prefs = ProviderPreferences::new()
.preferred_min_throughput(ThroughputThreshold::Percentile(
PercentileThresholds::new().p90(50.0)
));Sourcepub fn preferred_max_latency(self, threshold: LatencyThreshold) -> Self
pub fn preferred_max_latency(self, threshold: LatencyThreshold) -> Self
Set preferred maximum latency threshold.
Endpoints not meeting the threshold are deprioritized, not excluded.
Sourcepub fn max_price(self, price: MaxPrice) -> Self
pub fn max_price(self, price: MaxPrice) -> Self
Set maximum price ceiling.
If no eligible provider is at or under the ceiling, the request fails.
Sourcepub fn quantizations(
self,
quantizations: impl IntoIterator<Item = Quantization>,
) -> Self
pub fn quantizations( self, quantizations: impl IntoIterator<Item = Quantization>, ) -> Self
Restrict routing to providers serving specific quantization levels.
§Example
use rig::providers::openrouter::{ProviderPreferences, Quantization};
let prefs = ProviderPreferences::new()
.quantizations([Quantization::Int8, Quantization::Fp16]);Sourcepub fn zero_data_retention(self) -> Self
pub fn zero_data_retention(self) -> Self
Convenience: Enable Zero Data Retention
Sourcepub fn lowest_latency(self) -> Self
pub fn lowest_latency(self) -> Self
Convenience: Sort by latency (lower latency first)
Trait Implementations§
Source§impl Clone for ProviderPreferences
impl Clone for ProviderPreferences
Source§fn clone(&self) -> ProviderPreferences
fn clone(&self) -> ProviderPreferences
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProviderPreferences
impl Debug for ProviderPreferences
Source§impl Default for ProviderPreferences
impl Default for ProviderPreferences
Source§fn default() -> ProviderPreferences
fn default() -> ProviderPreferences
Source§impl<'de> Deserialize<'de> for ProviderPreferences
impl<'de> Deserialize<'de> for ProviderPreferences
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ProviderPreferences
impl PartialEq for ProviderPreferences
Source§impl Serialize for ProviderPreferences
impl Serialize for ProviderPreferences
impl StructuralPartialEq for ProviderPreferences
Auto Trait Implementations§
impl Freeze for ProviderPreferences
impl RefUnwindSafe for ProviderPreferences
impl Send for ProviderPreferences
impl Sync for ProviderPreferences
impl Unpin for ProviderPreferences
impl UnsafeUnpin for ProviderPreferences
impl UnwindSafe for ProviderPreferences
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
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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