Java client for the Langfuse API providing access to observability and analytics features for LLM applications
The Health API provides health check endpoints for monitoring API and database availability.
Client for checking API and database health.
/**
* Check health of API and database
*
* @param requestOptions Optional request configuration
* @return Health status response
* @throws ServiceUnavailableError if service is unavailable (503)
*/
HealthResponse health();
HealthResponse health(RequestOptions requestOptions);Usage Examples:
import com.langfuse.client.LangfuseClient;
import com.langfuse.client.resources.health.types.*;
import com.langfuse.client.resources.health.errors.*;
LangfuseClient client = LangfuseClient.builder()
.url("https://cloud.langfuse.com")
.credentials("pk-lf-...", "sk-lf-...")
.build();
try {
HealthResponse health = client.health().health();
System.out.println("Status: " + health.getStatus());
System.out.println("Version: " + health.getVersion());
} catch (ServiceUnavailableError e) {
System.err.println("Service unavailable: " + e.statusCode());
}/**
* Health check response
*/
public final class HealthResponse {
String getStatus(); // Health status (e.g., "ok")
String getVersion(); // API version
static Builder builder();
}The health endpoint may throw a ServiceUnavailableError (503 status code) when the service is unavailable.
import com.langfuse.client.resources.health.errors.ServiceUnavailableError;
try {
HealthResponse health = client.health().health();
// Service is healthy
} catch (ServiceUnavailableError e) {
// Service is unavailable
System.err.println("Service unavailable: " + e.getMessage());
System.err.println("Status code: " + e.statusCode());
}import com.langfuse.client.LangfuseClient;
import com.langfuse.client.resources.health.types.*;
import com.langfuse.client.resources.health.errors.*;
import java.util.concurrent.*;
public class HealthMonitor {
private final LangfuseClient client;
private final ScheduledExecutorService scheduler;
public HealthMonitor(LangfuseClient client) {
this.client = client;
this.scheduler = Executors.newScheduledThreadPool(1);
}
public void startMonitoring(int intervalSeconds) {
scheduler.scheduleAtFixedRate(
this::checkHealth,
0,
intervalSeconds,
TimeUnit.SECONDS
);
}
public void stopMonitoring() {
scheduler.shutdown();
}
private void checkHealth() {
try {
HealthResponse health = client.health().health();
System.out.println(
"[" + java.time.Instant.now() + "] " +
"Health: " + health.getStatus() +
", Version: " + health.getVersion()
);
} catch (ServiceUnavailableError e) {
System.err.println(
"[" + java.time.Instant.now() + "] " +
"Service unavailable (503)"
);
// Trigger alert
} catch (Exception e) {
System.err.println(
"[" + java.time.Instant.now() + "] " +
"Health check failed: " + e.getMessage()
);
}
}
public static void main(String[] args) {
LangfuseClient client = LangfuseClient.builder()
.url("https://cloud.langfuse.com")
.credentials("pk-lf-...", "sk-lf-...")
.build();
HealthMonitor monitor = new HealthMonitor(client);
// Check health every 30 seconds
monitor.startMonitoring(30);
// Keep running
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
monitor.stopMonitoring();
}
}
}public void initializeApplication() {
LangfuseClient client = LangfuseClient.builder()
.url("https://cloud.langfuse.com")
.credentials("pk-lf-...", "sk-lf-...")
.build();
// Check health before starting
try {
HealthResponse health = client.health().health();
System.out.println("Langfuse is available (version: " + health.getVersion() + ")");
} catch (ServiceUnavailableError e) {
System.err.println("WARNING: Langfuse is unavailable, starting in degraded mode");
}
}@RestController
public class HealthController {
private final LangfuseClient langfuseClient;
@GetMapping("/health/langfuse")
public ResponseEntity<String> checkLangfuseHealth() {
try {
HealthResponse health = langfuseClient.health().health();
return ResponseEntity.ok("Langfuse: " + health.getStatus());
} catch (ServiceUnavailableError e) {
return ResponseEntity.status(503).body("Langfuse unavailable");
}
}
}import io.github.resilience4j.circuitbreaker.CircuitBreaker;
public class LangfuseHealthCircuitBreaker {
private final LangfuseClient client;
private final CircuitBreaker circuitBreaker;
public boolean isHealthy() {
return circuitBreaker.executeSupplier(() -> {
try {
HealthResponse health = client.health().health();
return "ok".equals(health.getStatus());
} catch (ServiceUnavailableError e) {
return false;
}
});
}
}Install with Tessl CLI
npx tessl i tessl/maven-com-langfuse--langfuse-java