LLMClientRetry

org.llm4s.llmconnect.LLMClientRetry

Stateless helper functions for retrying LLM completion and streaming calls.

Retries only on recoverable errors (e.g. rate limit, timeout). Fails immediately on non-recoverable errors.

'''Retry delay precedence''' (honors upstream backpressure):

  • If the error provides a provider retry-delay hint (e.g. RateLimitError.retryDelay, ServiceError.retryDelay) and it is present and positive, that value is used so we do not retry before the server is ready.
  • Otherwise we fall back to local exponential backoff (baseDelay * 2^attempt) to avoid tight retry loops.
  • The chosen delay is always capped at 30 seconds so waits remain bounded.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def completeWithRetry(client: LLMClient, conversation: Conversation, options: CompletionOptions, maxAttempts: Int, baseDelay: FiniteDuration): Result[Completion]

Calls client.complete with retries on recoverable errors.

Calls client.complete with retries on recoverable errors.

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

options

completion options (default: CompletionOptions())

Attributes

Returns

Right(Completion) on success, Left(error) when retries exhausted, non-recoverable error, invalid input, or interrupted

def streamCompleteWithRetry(client: LLMClient, conversation: Conversation, options: CompletionOptions, maxAttempts: Int, baseDelay: FiniteDuration)(onChunk: StreamedChunk => Unit): Result[Completion]

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

Attributes

Returns

Right(Completion) on success, Left(error) when retries exhausted, non-recoverable error, invalid input, or interrupted