Stateless helper functions for retrying LLM completion and streaming calls.
Retries the errors RetryPolicy.isRetryable retries (e.g. rate limit, timeout, a 5xx), by the same rule. Fails immediately on any other error, including a client-error response.
Calls client.streamComplete with retries only when failure occurs before any chunk is emitted. Binary-compatible overload that delegates to the full version, sleeping the calling thread.
Calls client.streamComplete with retries only when failure occurs before any chunk is emitted. Binary-compatible overload that delegates to the full version, sleeping the calling thread.
Calls client.streamComplete with retries only when failure occurs before any chunk is emitted. Once streaming has started (at least one chunk delivered), any error is returned immediately without retry.
Calls client.streamComplete with retries only when failure occurs before any chunk is emitted. Once streaming has started (at least one chunk delivered), any error is returned immediately without retry.
Value parameters
baseDelay
base delay for backoff when provider retry-delay hints are absent (default: 1 second); must be positive
client
LLM client
conversation
conversation to complete
maxAttempts
maximum attempts including the first (default: 3); must be positive
onChunk
callback for each streamed chunk
options
completion options (default: CompletionOptions())
sleepFn
function used to pause between retries (default: sleeps the calling thread); override for testing
Attributes
Returns
Right(Completion) on success, Left(error) when retries exhausted, non-recoverable error, invalid input, or interrupted