pub struct HeaderProfile { /* private fields */ }provider-headers only.Expand description
One provider’s header convention.
Use a built-in profile (HeaderProfile::OPENAI and friends) and call
parse.
Implementations§
Source§impl HeaderProfile
impl HeaderProfile
Sourcepub const OPENAI: Self
pub const OPENAI: Self
OpenAI: x-ratelimit-{limit,remaining,reset}-{requests,tokens}, reset as a
duration string, plus retry-after.
Sourcepub const ANTHROPIC: Self
pub const ANTHROPIC: Self
Anthropic: anthropic-ratelimit-{requests,tokens}-{limit,remaining,reset},
reset as an RFC 3339 instant, plus retry-after.
Sourcepub const GITHUB: Self
pub const GITHUB: Self
GitHub: x-ratelimit-{limit,remaining,reset}, reset as an absolute Unix
timestamp, plus retry-after.
Sourcepub const RFC: Self
pub const RFC: Self
The IETF RateLimit header draft: RateLimit-{Limit,Remaining,Reset},
reset as delta-seconds, plus Retry-After. A reasonable default for
standards-compliant or unknown APIs.
Sourcepub const STRIPE: Self
pub const STRIPE: Self
Stripe: no standard rate-limit headers; it signals back-off with
Retry-After on a 429.
Sourcepub fn parse(&self, headers: &[(&str, &str)]) -> RateLimitInfo
pub fn parse(&self, headers: &[(&str, &str)]) -> RateLimitInfo
Parses headers into a RateLimitInfo, using the system clock to
resolve absolute reset timestamps.
headers is a slice of (name, value) pairs; lookups are
case-insensitive.
§Examples
use throttle_net::provider::HeaderProfile;
let headers = [
("x-ratelimit-limit-requests", "100"),
("x-ratelimit-remaining-requests", "42"),
("x-ratelimit-reset-requests", "1s"),
];
let info = HeaderProfile::OPENAI.parse(&headers);
let requests = info.requests.unwrap();
assert_eq!(requests.limit, Some(100));
assert_eq!(requests.remaining, Some(42));Trait Implementations§
Source§impl Clone for HeaderProfile
impl Clone for HeaderProfile
Source§fn clone(&self) -> HeaderProfile
fn clone(&self) -> HeaderProfile
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more