struct

Anthropic::RetryPolicy

Inherits Struct < Value < Object

Retry policy for transient API errors.

Constants

DEFAULT_BACKOFF_FACTOR = 2.0
DEFAULT_BASE_DELAY = 1.second
DEFAULT_MAX_DELAY = 10.seconds
DEFAULT_MAX_RETRIES = 2

Default: 2 retries with exponential backoff (1s, 2s, max 10s)

Constructors

aggressive

Aggressive retry policy (5 retries, longer delays)

Source
default

Default retry policy

Source
disabled

No retries - disabled policy

Source
new(max_retries : Int32 = DEFAULT_MAX_RETRIES, base_delay : Time::Span = DEFAULT_BASE_DELAY, max_delay : Time::Span = DEFAULT_MAX_DELAY, backoff_factor : Float64 = DEFAULT_BACKOFF_FACTOR)
Source

Class methods

retryable?(error : Exception) : Bool

Whether an error is retryable (429 rate limit, 529 overloaded, 408 timeout, generic 5xx server errors, or network errors)

Source

Instance methods

backoff_factor
Source
base_delay
Source
delay_for(attempt : Int32) : Time::Span

Calculate delay for a given attempt number (0-indexed). Uses exponential backoff: base_delay * (backoff_factor ^ attempt)

Source
enabled?

Whether retries are enabled

Source
max_delay
Source
max_retries
Source