Class LLMHealthIndicator

java.lang.Object
com.tnsai.quality.observability.health.LLMHealthIndicator
All Implemented Interfaces:
HealthIndicator

public class LLMHealthIndicator extends Object implements HealthIndicator
Health indicator for LLM providers.

Checks LLM client health by:

  • Verifying client configuration
  • Optionally making a test call (ping)
  • Checking recent call success rate
  • Monitoring response latency

Example usage:


 LLMClient client = new OpenAIClient();

 // Basic health indicator (no ping)
 HealthRegistry.getInstance()
     .register(new LLMHealthIndicator(client, "openai"));

 // With ping check (makes actual API call)
 HealthRegistry.getInstance()
     .register(new LLMHealthIndicator(client, "openai", true));
 

Note: Enabling ping checks will make actual API calls, which may incur costs and add latency to health checks.

See Also:
  • Constructor Details

    • LLMHealthIndicator

      public LLMHealthIndicator(com.tnsai.llm.LLMClient client, String providerName)
      Creates an LLM health indicator without ping.
      Parameters:
      client - the LLM client
      providerName - the provider name (e.g., "openai", "anthropic")
    • LLMHealthIndicator

      public LLMHealthIndicator(com.tnsai.llm.LLMClient client, String providerName, boolean enablePing)
      Creates an LLM health indicator.
      Parameters:
      client - the LLM client
      providerName - the provider name
      enablePing - whether to make test API calls
    • LLMHealthIndicator

      public LLMHealthIndicator(com.tnsai.llm.LLMClient client, String providerName, boolean enablePing, double maxLatencyMs, double minSuccessRate)
      Creates an LLM health indicator with custom thresholds.
      Parameters:
      client - the LLM client
      providerName - the provider name
      enablePing - whether to make test API calls
      maxLatencyMs - maximum acceptable latency in milliseconds
      minSuccessRate - minimum success rate (0.0-1.0)
  • Method Details

    • getName

      public String getName()
      Description copied from interface: HealthIndicator
      Gets the name of this health indicator.

      Default implementation returns the simple class name.

      Specified by:
      getName in interface HealthIndicator
      Returns:
      the indicator name
    • check

      public HealthCheckResult check()
      Description copied from interface: HealthIndicator
      Performs the health check and returns the result.

      Implementations should:

      • Return quickly (under 10 seconds)
      • Not throw exceptions (return DOWN status instead)
      • Include relevant details in the result
      Specified by:
      check in interface HealthIndicator
      Returns:
      the health check result
    • getTimeout

      public Duration getTimeout()
      Description copied from interface: HealthIndicator
      Gets the timeout for this health check.
      Specified by:
      getTimeout in interface HealthIndicator
      Returns:
      the timeout duration
    • builder

      public static LLMHealthIndicator.Builder builder()