Skip to main content

Retrying

Struct Retrying 

Source
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>

Source

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).

Source

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: Clone + Provider> Clone for Retrying<P>

Source§

fn clone(&self) -> Retrying<P>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + Provider> Debug for Retrying<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: Provider> Provider for Retrying<P>

Source§

async fn chat_completion( &self, request: &ChatCompletionRequest, ) -> Result<ChatCompletionResponse, Error>

Source§

async fn chat_completion_stream( &self, request: &ChatCompletionRequest, ) -> Result<BoxStream<'static, Result<ChatCompletionChunk, Error>>, Error>

Source§

async fn anthropic_messages( &self, request: &AnthropicRequest, ) -> Result<AnthropicResponse, Error>

Source§

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>

Gemini Generative Language API: :streamGenerateContent. Read more
Source§

async fn embedding( &self, request: &EmbeddingRequest, ) -> Result<EmbeddingResponse, Error>

Source§

async fn image_generation( &self, request: &ImageRequest, ) -> Result<(Bytes, String), Error>

Source§

async fn audio_speech( &self, request: &AudioSpeechRequest, ) -> Result<(Bytes, String), Error>

Source§

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

Gemini Generative Language API: :generateContent. Read more
Source§

fn complete( &self, _request: &Request, ) -> impl Future<Output = Result<Response, Error>> + Send

Source§

fn complete_stream( &self, _request: &Request, ) -> impl Future<Output = Result<BoxStream<'static, Result<StreamEvent, Error>>, Error>> + Send

Source§

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

Whether this provider speaks the Anthropic wire format and can forward raw /v1/messages bytes without translation.
Source§

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

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

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

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

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

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

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

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V