package ocaml-ai-sdk

  1. Overview
  2. Docs
OCaml AI SDK - Provider abstraction for AI models

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ocaml-ai-sdk-0.6.2.tbz
sha256=637f60398f673dfb2e661f6ed7da169b823a870d27b48e729d5b9200e46a52b2
sha512=5aec259473395025edb6689b544e57e821cfbef9352987f95eb2182034979ce898040e06e60a9d89a40a187b77fb5b1b7183c7ec4264da9d9a834864860a5fed

doc/ocaml-ai-sdk.ai_core/Ai_core/Retry/index.html

Module Ai_core.RetrySource

Retry with exponential backoff for provider calls.

Wraps a thunk and retries on retryable Provider_error exceptions and transient network errors (Unix.Unix_error with ECONNRESET, ETIMEDOUT, etc.). Other errors are re-raised immediately. Matches upstream AI SDK retry behavior.

Sourcetype retry_reason =
  1. | Max_retries_exceeded
  2. | Error_not_retryable
Sourcetype retry_error = {
  1. message : string;
  2. reason : retry_reason;
  3. errors : exn list;
}
Sourceexception Retry_error of retry_error
Sourceval reason_to_string : retry_reason -> string
Sourceval with_retries : ?max_retries:int -> ?initial_delay_ms:int -> ?backoff_factor:int -> ?max_retry_delay_ms:int -> ?sleep:(float -> unit Lwt.t) -> ?random:(unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t

Retry a thunk with exponential backoff.

  • parameter max_retries

    Number of additional attempts after the initial call (default 2, matching upstream). Total attempts = 1 + max_retries. Set to 0 to disable retries (only the initial call is made).

  • parameter initial_delay_ms

    Initial delay in milliseconds (default 2000).

  • parameter backoff_factor

    Multiplier applied to delay after each retry (default 2).

A server retry_after_s hint on the error, when present and reasonable, REPLACES the exponential backoff for that attempt (it may shorten as well as lengthen the delay — it is not a lower bound). Following upstream, a hint of ms milliseconds is reasonable iff ms >= 0 and either ms < 60000 or ms is below the un-jittered exponential delay for this attempt. Rejected hints fall back to the jittered exponential backoff. Jitter never applies to an accepted hint.

  • parameter max_retry_delay_ms

    Optional maximum retry sleep. An ordinary (backoff) delay above this limit is clamped down to it; an accepted server hint above this limit instead stops retrying immediately, without sleeping or issuing another request.

  • parameter sleep

    Function called to sleep between retries (default Lwt_unix.sleep).

  • parameter random

    Random source in [0, 1)] used for bounded jitter.