pub struct KeyPool { /* private fields */ }Expand description
Thread-safe key pool managing multiple API keys across endpoints.
Implementations§
Source§impl KeyPool
impl KeyPool
pub fn new() -> Self
Sourcepub async fn register_endpoint(&self, endpoint: &str, env_vars: Vec<String>)
pub async fn register_endpoint(&self, endpoint: &str, env_vars: Vec<String>)
Register keys for an endpoint. Merges with any existing keys. Resolution order: process env → OS keychain (see module docs).
Sourcepub async fn lease(&self, endpoint: &str) -> Option<KeyLease>
pub async fn lease(&self, endpoint: &str) -> Option<KeyLease>
Lease a key for the given endpoint. Returns None if no keys available.
Sourcepub async fn lease_or_env(
&self,
endpoint: &str,
fallback_env: &str,
) -> Option<KeyLease>
pub async fn lease_or_env( &self, endpoint: &str, fallback_env: &str, ) -> Option<KeyLease>
Lease a key, falling back to a single env var (or keychain) if the
endpoint isn’t registered. This provides backward compatibility with
the single-key model and triggers the same env→keychain resolution
order as register_endpoint.
Sourcepub async fn report_success(
&self,
endpoint: &str,
env_var: &str,
latency_ms: u64,
input_tokens: u64,
output_tokens: u64,
)
pub async fn report_success( &self, endpoint: &str, env_var: &str, latency_ms: u64, input_tokens: u64, output_tokens: u64, )
Report a successful request.
Sourcepub async fn report_failure(
&self,
endpoint: &str,
env_var: &str,
is_rate_limit: bool,
)
pub async fn report_failure( &self, endpoint: &str, env_var: &str, is_rate_limit: bool, )
Report a failed request.
Sourcepub async fn endpoint_stats(&self, endpoint: &str) -> Vec<KeyStats>
pub async fn endpoint_stats(&self, endpoint: &str) -> Vec<KeyStats>
Get stats for all keys on an endpoint.
Sourcepub async fn total_keys(&self) -> usize
pub async fn total_keys(&self) -> usize
Total key count across all endpoints.
Sourcepub async fn available_keys(&self, endpoint: &str) -> usize
pub async fn available_keys(&self, endpoint: &str) -> usize
Get the number of available (non-rate-limited) keys for an endpoint.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for KeyPool
impl !RefUnwindSafe for KeyPool
impl Send for KeyPool
impl Sync for KeyPool
impl Unpin for KeyPool
impl UnsafeUnpin for KeyPool
impl !UnwindSafe for KeyPool
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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