Java client for the Langfuse API providing access to observability and analytics features for LLM applications
npx @tessl/cli install tessl/maven-com-langfuse--langfuse-java@0.1.0Langfuse Java Client is an auto-generated Java API client for Langfuse, an open-source observability and analytics platform for LLM applications. This client enables Java developers to interact with the Langfuse API for managing traces, observations, prompts, datasets, scores, and other observability features. Built with Maven, it leverages Jackson for JSON serialization and OkHttp for HTTP communication.
pom.xml:<dependency>
<groupId>com.langfuse</groupId>
<artifactId>langfuse-java</artifactId>
<version>0.1.0</version>
</dependency>import com.langfuse.client.LangfuseClient;
import com.langfuse.client.core.LangfuseClientApiException;For specific functionality, import the relevant types:
// Prompts
import com.langfuse.client.resources.prompts.types.*;
// Traces and observations
import com.langfuse.client.resources.trace.types.*;
import com.langfuse.client.resources.observations.types.*;
// Ingestion (primary tracing API)
import com.langfuse.client.resources.ingestion.types.*;
// Common types
import com.langfuse.client.resources.commons.types.*;import com.langfuse.client.LangfuseClient;
import com.langfuse.client.core.LangfuseClientApiException;
import com.langfuse.client.resources.prompts.types.PromptMetaListResponse;
public class LangfuseExample {
public static void main(String[] args) {
// Initialize client with credentials
LangfuseClient client = LangfuseClient.builder()
.url("https://cloud.langfuse.com") // EU data region
// .url("https://us.cloud.langfuse.com") // US data region
// .url("http://localhost:3000") // Local deployment
.credentials("pk-lf-...", "sk-lf-...")
.build();
// Make API requests
try {
PromptMetaListResponse prompts = client.prompts().list();
System.out.println("Prompts: " + prompts);
} catch (LangfuseClientApiException error) {
System.err.println("Error: " + error.statusCode());
System.err.println("Body: " + error.body());
}
}
}The Langfuse Java client is organized around several key components:
The client provides access to 21 specialized resource clients, each managing a specific area of the Langfuse API:
Configure the LangfuseClient with credentials, custom URLs, headers, and HTTP settings.
// Builder interface
public static LangfuseClientBuilder builder();
// Build configured client
public LangfuseClient build();Batch ingestion of tracing events including traces, observations (spans, events, generations), and scores. This is the primary API for tracing operations, supporting event deduplication and multiple event types in a single batch.
/**
* Batch ingestion for Langfuse tracing
* Supports event deduplication, handles multiple event types
* Batch sizes limited to 3.5 MB
* Returns 207 status with error details instead of 4xx for input errors
*/
IngestionResponse batch(IngestionRequest request);
IngestionResponse batch(IngestionRequest request, RequestOptions requestOptions);Retrieve and delete traces with filtering and pagination.
// Get a specific trace with full details
TraceWithFullDetails get(String traceId);
// List traces with filters
Traces list();
Traces list(GetTracesRequest request);
// Delete trace(s)
DeleteTraceResponse delete(String traceId);
DeleteTraceResponse deleteMultiple(DeleteTracesRequest request);Retrieve observations (spans, events, generations) with extensive filtering options.
// Get a specific observation
ObservationsView get(String observationId);
// List observations with filters
ObservationsViews getMany();
ObservationsViews getMany(GetObservationsRequest request);Manage prompt templates in text and chat formats with versioning and labels.
// Get prompt by name with optional version/label
Prompt get(String promptName);
Prompt get(String promptName, GetPromptRequest request);
// List all prompts with metadata
PromptMetaListResponse list();
// Create new prompt version
Prompt create(CreatePromptRequest request);Create and manage datasets for evaluation, including dataset items and runs.
// List datasets
PaginatedDatasets list();
// Get dataset
Dataset get(String datasetName);
// Create dataset
Dataset create(CreateDatasetRequest request);
// Get dataset run with items
DatasetRunWithItems getRun(String datasetName, String runName);Create, retrieve, and configure scores for traces and observations.
// Create score
CreateScoreResponse create(CreateScoreRequest request);
// Get scores with extensive filtering (v2 API)
GetScoresResponse get();
GetScoresResponse get(GetScoresRequest request);
// Delete score
void delete(String scoreId);Retrieve sessions and their associated traces.
// List sessions
PaginatedSessions list();
PaginatedSessions list(GetSessionsRequest request);
// Get session with all traces
SessionWithTraces get(String sessionId);Manage LLM model definitions and pricing configurations.
// Create model
Model create(CreateModelRequest request);
// List models
PaginatedModels list();
// Get model
Model get(String id);
// Delete model
void delete(String id);Query project metrics using a JSON query object.
MetricsResponse metrics(GetMetricsRequest request);Manage comments on traces, observations, sessions, and prompts. Manage annotation queues for human review workflows.
// Create comment
CreateCommentResponse create(CreateCommentRequest request);
// Get comments
GetCommentsResponse get();
// Manage annotation queues
PaginatedAnnotationQueues listQueues();
AnnotationQueue getQueue(String queueId);Manage projects, API keys, and organization memberships (requires organization-scoped API key for most operations).
// Get projects
Projects get();
// Create project (requires org-scoped key)
Project create(CreateProjectRequest request);
// Manage API keys (requires org-scoped key)
ApiKeyList getApiKeys(String projectId);
ApiKeyResponse createApiKey(String projectId, CreateApiKeyRequest request);SCIM 2.0 user provisioning for organization user management (requires organization-scoped API key).
// List users
ScimUsersListResponse listUsers();
ScimUsersListResponse listUsers(ListUsersRequest request);
// Create user
ScimUser createUser(CreateUserRequest request);
// Get user
ScimUser getUser(String userId);Get media records and presigned upload URLs for media files.
// Get media record
GetMediaResponse get(String mediaId);
// Get presigned upload URL
GetMediaUploadUrlResponse getUploadUrl(GetMediaUploadUrlRequest request);Check API and database health.
HealthResponse health();