pub struct Retrying<P: Provider> { /* private fields */ }Expand description
A Provider wrapper that retries transient failures with exponential
backoff and full jitter, and bounds each attempt with a per-call timeout.
429s whose retry_after exceeds max_retry_after are propagated
immediately — the upstream is signalling a wait longer than this wrapper
is willing to block for.
Implementations§
Source§impl<P: Provider> Retrying<P>
impl<P: Provider> Retrying<P>
Sourcepub fn new(inner: P) -> Self
pub fn new(inner: P) -> Self
Wrap a provider with the default retry policy (2 retries, 30s timeout, 60s max retry-after, 100ms initial backoff).
Sourcepub fn max_retry_after(self, d: Duration) -> Self
pub fn max_retry_after(self, d: Duration) -> Self
Override the maximum Retry-After duration this wrapper will honor.
429s above this threshold are propagated as non-retryable.
Trait Implementations§
Source§impl<P: Provider> Provider for Retrying<P>
impl<P: Provider> Provider for Retrying<P>
async fn chat_completion( &self, request: &ChatCompletionRequest, ) -> Result<ChatCompletionResponse, Error>
async fn chat_completion_stream( &self, request: &ChatCompletionRequest, ) -> Result<BoxStream<'static, Result<ChatCompletionChunk, Error>>, Error>
async fn anthropic_messages( &self, request: &AnthropicRequest, ) -> Result<AnthropicResponse, Error>
async fn anthropic_messages_stream( &self, request: &AnthropicRequest, ) -> Result<BoxStream<'static, Result<AnthropicStreamEvent, Error>>, Error>
Source§async fn gemini_generate_content_stream(
&self,
model: &str,
request: &GeminiRequest,
) -> Result<BoxStream<'static, Result<GeminiResponse, Error>>, Error>
async fn gemini_generate_content_stream( &self, model: &str, request: &GeminiRequest, ) -> Result<BoxStream<'static, Result<GeminiResponse, Error>>, Error>
Gemini Generative Language API:
:streamGenerateContent. Read moreasync fn embedding( &self, request: &EmbeddingRequest, ) -> Result<EmbeddingResponse, Error>
async fn image_generation( &self, request: &ImageRequest, ) -> Result<(Bytes, String), Error>
async fn audio_speech( &self, request: &AudioSpeechRequest, ) -> Result<(Bytes, String), Error>
async fn audio_transcription( &self, model: &str, fields: &[MultipartField], ) -> Result<(Bytes, String), Error>
Source§fn gemini_generate_content(
&self,
model: &str,
request: &GeminiRequest,
) -> impl Future<Output = Result<GeminiResponse, Error>> + Send
fn gemini_generate_content( &self, model: &str, request: &GeminiRequest, ) -> impl Future<Output = Result<GeminiResponse, Error>> + Send
Gemini Generative Language API:
:generateContent. Read morefn complete( &self, _request: &Request, ) -> impl Future<Output = Result<Response, Error>> + Send
fn complete_stream( &self, _request: &Request, ) -> impl Future<Output = Result<BoxStream<'static, Result<StreamEvent, Error>>, Error>> + Send
Source§fn is_openai_compat(&self) -> bool
fn is_openai_compat(&self) -> bool
Whether this provider speaks the OpenAI wire format and can forward
raw JSON bytes without deserialization.
Source§fn is_anthropic_compat(&self) -> bool
fn is_anthropic_compat(&self) -> bool
Whether this provider speaks the Anthropic wire format and can
forward raw
/v1/messages bytes without translation.Source§fn is_gemini_compat(&self) -> bool
fn is_gemini_compat(&self) -> bool
Whether this provider speaks the Gemini wire format and can
forward raw
:generateContent bytes without translation.Source§fn chat_completion_stream_passthrough(
&self,
_model: &str,
_body_stream: ByteStream,
) -> impl Future<Output = Result<ByteStream, Error>> + Send
fn chat_completion_stream_passthrough( &self, _model: &str, _body_stream: ByteStream, ) -> impl Future<Output = Result<ByteStream, Error>> + Send
Stream a request body directly to an OpenAI-compatible endpoint and
return the raw SSE response stream. The body is consumed — no retries.
Source§fn chat_completion_stream_raw(
&self,
_model: &str,
_raw_body: Bytes,
) -> impl Future<Output = Result<ByteStream, Error>> + Send
fn chat_completion_stream_raw( &self, _model: &str, _raw_body: Bytes, ) -> impl Future<Output = Result<ByteStream, Error>> + Send
Stream raw OpenAI SSE bytes from an OpenAI-compatible endpoint.
The default returns
not_implemented. OpenAI-compatible providers
override to forward bytes without deserialization.Source§fn chat_completion_raw(
&self,
_model: &str,
raw_body: Bytes,
) -> impl Future<Output = Result<Bytes, Error>> + Send
fn chat_completion_raw( &self, _model: &str, raw_body: Bytes, ) -> impl Future<Output = Result<Bytes, Error>> + Send
Forward raw OpenAI-format JSON body and return raw response bytes.
The default deserializes, calls
chat_completion,
and re-serializes. OpenAI-compatible providers override to skip serde.Source§fn anthropic_messages_raw(
&self,
_raw_body: Bytes,
) -> impl Future<Output = Result<Bytes, Error>> + Send
fn anthropic_messages_raw( &self, _raw_body: Bytes, ) -> impl Future<Output = Result<Bytes, Error>> + Send
Forward raw Anthropic-format JSON body and return raw response bytes.
The default translates Anthropic → OpenAI, calls [
chat_completion],
and translates back. The Anthropic provider overrides to skip serde.Source§fn anthropic_messages_stream_raw(
&self,
_raw_body: Bytes,
) -> impl Future<Output = Result<ByteStream, Error>> + Send
fn anthropic_messages_stream_raw( &self, _raw_body: Bytes, ) -> impl Future<Output = Result<ByteStream, Error>> + Send
Stream raw Anthropic SSE bytes from an Anthropic-compatible endpoint.
Source§fn gemini_generate_content_raw(
&self,
model: &str,
raw_body: Bytes,
) -> impl Future<Output = Result<Bytes, Error>> + Send
fn gemini_generate_content_raw( &self, model: &str, raw_body: Bytes, ) -> impl Future<Output = Result<Bytes, Error>> + Send
Forward raw Gemini-format JSON body and return raw response bytes.
Defaults to deserialize →
gemini_generate_content → re-serialize.
Gemini-compatible providers override to skip serde.Source§fn gemini_generate_content_stream_raw(
&self,
_model: &str,
_raw_body: Bytes,
) -> impl Future<Output = Result<ByteStream, Error>> + Send
fn gemini_generate_content_stream_raw( &self, _model: &str, _raw_body: Bytes, ) -> impl Future<Output = Result<ByteStream, Error>> + Send
Stream raw Gemini SSE bytes from a Gemini-compatible endpoint.
Auto Trait Implementations§
impl<P> Freeze for Retrying<P>where
P: Freeze,
impl<P> RefUnwindSafe for Retrying<P>where
P: RefUnwindSafe,
impl<P> Send for Retrying<P>
impl<P> Sync for Retrying<P>
impl<P> Unpin for Retrying<P>where
P: Unpin,
impl<P> UnsafeUnpin for Retrying<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for Retrying<P>where
P: UnwindSafe,
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