org.llm4s.reliability

Members list

Type members

Classlikes

@Stable
final case class CircuitBreakerConfig

Circuit breaker configuration for service resilience.

Circuit breaker configuration for service resilience.

Value parameters

failureThreshold

Number of consecutive failures before opening circuit

recoveryTimeout

Time to wait before attempting recovery (half-open state)

successThreshold

Number of successes in half-open state to close circuit

Attributes

Companion
object
Source
ReliabilityConfig.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
ReliabilityConfig.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
sealed trait CircuitState

Circuit breaker state.

Circuit breaker state.

Attributes

Companion
object
Source
ReliableClient.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Closed
object HalfOpen
object Open
object CircuitState

Attributes

Companion
trait
Source
ReliableClient.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
final case class RateLimitConfig

Local token-bucket rate limiting configuration.

Local token-bucket rate limiting configuration.

Value parameters

burstCapacity

Maximum tokens the bucket can hold, i.e. the largest burst allowed

enabled

Whether local rate limiting is applied

requestsPerMinute

Sustained request rate once the bucket is empty

Attributes

Companion
object
Source
ReliabilityConfig.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
ReliabilityConfig.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
final case class ReliabilityConfig

Configuration for reliable LLM provider calls.

Configuration for reliable LLM provider calls.

Provides retry logic, circuit breakers, and deadline enforcement to make LLM API calls resilient to transient failures.

Construction does not check the values, so that a configuration can be built up with setters; validate does, and a ReliableClient given a configuration that fails it returns that error from every call.

Value parameters

circuitBreaker

Circuit breaker configuration

deadline

Time allowed for all the attempts of one call together, waits included; checked between attempts, so it stops further retries but does not interrupt an attempt in flight

enabled

Whether reliability features are enabled (for opt-out)

rateLimit

Local rate limiting configuration

retryPolicy

Retry policy for transient failures

Attributes

Companion
object
Source
ReliabilityConfig.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
ReliabilityConfig.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Experimental

The metrics ReliableClient records, declared as Metrics and recorded through MetricsCollector.increment, so every backend that exports generic metrics exports them, with no method of its own to implement (#2801). They were three methods of MetricsCollector with no-op defaults - recordRetryAttempt, recordCircuitBreakerTransition and recordError - which a backend that did not override them dropped silently, as the Prometheus one did.

The metrics ReliableClient records, declared as Metrics and recorded through MetricsCollector.increment, so every backend that exports generic metrics exports them, with no method of its own to implement (#2801). They were three methods of MetricsCollector with no-op defaults - recordRetryAttempt, recordCircuitBreakerTransition and recordError - which a backend that did not override them dropped silently, as the Prometheus one did.

A Prometheus backend exposes them as llm4s_retries_total, llm4s_circuit_breaker_transitions_total and llm4s_reliability_errors_total; a Micrometer one under the names below.

Attributes

Source
ReliabilityMetrics.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Stable
final class ReliableClient extends LLMClient

Wrapper that adds reliability features to any LLMClient.

Wrapper that adds reliability features to any LLMClient.

Provides:

  • Retry with configurable policies (exponential backoff, linear, fixed)
  • Circuit breaker to fail fast when service is down: while the circuit is open, or half-open with a probe in flight, a call is refused with a CircuitOpenError, which is not retried
  • A deadline on the attempts taken together: it is checked before each attempt and before each wait, so no retry starts once it has passed. It does not interrupt an attempt: a call hung inside the underlying client is bounded by that client's own timeout, not by the deadline
  • Local token-bucket rate limiting (RateLimitConfig), checked before every attempt
  • Metrics for retry attempts, circuit breaker transitions and the errors it ends on (ReliabilityMetrics)

Thread-safety: Uses AtomicInteger/AtomicReference for circuit breaker state management to ensure correct behavior under concurrent access.

A configuration the client cannot run with (ReliabilityConfig.validate: a failureThreshold below 1, a burstCapacity below 1, a negative requestsPerMinute) does not throw here: every call, and validate(), returns its ValidationError.

Build one with the companion's apply, and add a collector with withMetrics:

val reliable = ReliableClient(client, "openai-main", ReliabilityConfig.default).withMetrics(collector)

The constructor is private, so that a setting can be added without breaking a caller.

Attributes

Companion
object
Source
ReliableClient.scala
Supertypes
trait LLMClient
class Object
trait Matchable
class Any

Attributes

Companion
class
Source
ReliableClient.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Stable
sealed trait RetryPolicy

Retry policy for transient failures.

Retry policy for transient failures.

Defines how many times to retry and how long to wait between attempts.

Attributes

Companion
object
Source
RetryPolicy.scala
Supertypes
class Object
trait Matchable
class Any
object RetryPolicy

Attributes

Companion
trait
Source
RetryPolicy.scala
Supertypes
class Object
trait Matchable
class Any
Self type