or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

client-configuration.mdcomments-annotations.mdcommon-types.mddatasets.mdexceptions.mdhealth.mdindex.mdingestion.mdmedia.mdmetrics.mdmodels.mdpagination.mdprojects-organizations.mdprompts.mdscim.mdscores.mdsessions.mdtraces-observations.md
tile.json

tessl/maven-com-langfuse--langfuse-java

Java client for the Langfuse API providing access to observability and analytics features for LLM applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.langfuse/langfuse-java@0.1.x

To install, run

npx @tessl/cli install tessl/maven-com-langfuse--langfuse-java@0.1.0

index.mddocs/

Langfuse Java Client

Langfuse 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.

Package Information

  • Package Name: langfuse-java
  • Group ID: com.langfuse
  • Artifact ID: langfuse-java
  • Package Type: maven
  • Language: Java
  • Installation: Add dependency to pom.xml:
<dependency>
    <groupId>com.langfuse</groupId>
    <artifactId>langfuse-java</artifactId>
    <version>0.1.0</version>
</dependency>

Core Imports

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.*;

Basic Usage

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

Architecture

The Langfuse Java client is organized around several key components:

Main Client

  • LangfuseClient: Entry point providing access to all resource-specific clients
  • LangfuseClientBuilder: Builder pattern for configuring client instances with custom URLs, credentials, headers, and HTTP settings

Resource Clients

The client provides access to 21 specialized resource clients, each managing a specific area of the Langfuse API:

  • Tracing: IngestionClient (batch tracing), TraceClient, ObservationsClient, SessionsClient
  • Prompts: PromptsClient, PromptVersionClient
  • Datasets: DatasetsClient, DatasetItemsClient, DatasetRunItemsClient
  • Scoring: ScoreClient, ScoreV2Client, ScoreConfigsClient
  • Models: ModelsClient
  • Metrics: MetricsClient
  • Comments & Annotations: CommentsClient, AnnotationQueuesClient
  • Organization Management: ProjectsClient, OrganizationsClient, ScimClient
  • Media: MediaClient
  • Health: HealthClient

Type System

  • Request Types: Builder-based request objects with staged builders for required fields
  • Response Types: Immutable response objects with getters
  • Common Types: Shared domain objects (Trace, Observation, Score, Dataset, etc.)
  • Union Types: Type-safe polymorphic data (Score variants, Prompt variants, Event types)
  • Enums: Type-safe constants for status values, data types, and configuration options

Error Handling

  • LangfuseClientException: Base exception for SDK errors
  • LangfuseClientApiException: Exception for non-2XX responses with status code and body
  • Specific Errors: UnauthorizedError, AccessDeniedError, NotFoundError, etc.

Configuration

  • ClientOptions: Client-level configuration (environment, headers, HTTP client, timeout)
  • RequestOptions: Per-request overrides for headers and timeout
  • Environment: Configurable API base URL (cloud EU, cloud US, or custom)

Capabilities

Client Configuration

Configure the LangfuseClient with credentials, custom URLs, headers, and HTTP settings.

// Builder interface
public static LangfuseClientBuilder builder();

// Build configured client
public LangfuseClient build();

Client Configuration

Tracing via Ingestion API

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

Ingestion API

Trace Management

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

Traces and Observations

Observation Management

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

Traces and Observations

Prompt Management

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

Prompts

Dataset Management

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

Datasets

Score Management

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

Scores

Session Management

Retrieve sessions and their associated traces.

// List sessions
PaginatedSessions list();
PaginatedSessions list(GetSessionsRequest request);

// Get session with all traces
SessionWithTraces get(String sessionId);

Sessions

Model Management

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

Models

Metrics

Query project metrics using a JSON query object.

MetricsResponse metrics(GetMetricsRequest request);

Metrics

Comments and Annotations

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

Comments and Annotations

Project and Organization Management

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

Projects and Organizations

SCIM User Provisioning

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

SCIM

Media Management

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

Media

Health Checks

Check API and database health.

HealthResponse health();

Health

Additional Resources

Notes

  • This client is auto-generated from the Langfuse API specification using Fern
  • The recommended approach for tracing is via OpenTelemetry instrumentation rather than direct Ingestion API usage
  • Most methods provide 3 overloads: no parameters, with request object, with request and RequestOptions
  • All list endpoints support pagination with consistent MetaResponse format
  • Organization-level operations require organization-scoped API keys