This repository contains an auto-generated Langfuse API client for Java based on our API specification. See the Langfuse API reference for more details on the available endpoints.
OpenTelemetry is the recommended β and, going forward, the only supported β way to send tracing data to Langfuse from Java. This client no longer exposes the legacy ingestion API; it is deprecated and is removed in Langfuse v4.
Instrument your application with the OpenTelemetry Java SDK and export spans over OTLP/HTTP to the Langfuse OTel endpoint:
OTEL_EXPORTER_OTLP_ENDPOINT="https://cloud.langfuse.com/api/public/otel"
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic ${AUTH_STRING},x-langfuse-ingestion-version=4"The x-langfuse-ingestion-version: 4 header selects the v4 ingestion path. It is not sufficient on its own β spans also have to follow the v4 span format. Read Migrate custom ingestion to Langfuse v4 before switching production traffic; it covers the v4-ready checklist, the legacy event β OTel span mapping, and propagating trace context to every observation.
Going through OpenTelemetry also means you do not have to handle batching, retries, or observation updates yourself. Check out our Spring AI example for a full setup.
Use this client for everything that is not tracing ingestion: prompts, datasets, scores, models, comments, annotation queues, and the reading APIs.
The recommended way to install the langfuse-java API client is via Maven Central:
<dependency>
<groupId>com.langfuse</groupId>
<artifactId>langfuse-java</artifactId>
<version>0.3.0</version>
</dependency>Instantiate the Langfuse Client with the respective endpoint and your API Keys.
import com.langfuse.client.LangfuseClient;
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();An async client is also available via AsyncLangfuseClient.builder() with the same configuration options.
Make requests using the clients:
import com.langfuse.client.core.LangfuseClientApiException;
import com.langfuse.client.resources.prompts.types.PromptMetaListResponse;
try {
PromptMetaListResponse prompts = client.prompts().list();
} catch (LangfuseClientApiException error) {
System.out.println(error.body());
System.out.println(error.statusCode());
}Langfuse v4 uses an observations-first data model. The endpoints built on the v3 model are deprecated: Langfuse Cloud serves them until November 16, 2026, and they become unavailable in self-hosted deployments as soon as those upgrade to v4.
Those endpoints have been removed from this client so that it only exposes the API surface that survives the v4 cutover. The canonical, per-endpoint migration reference is Migration of deprecated APIs; the Versions & Compatibility matrix lists which endpoints work against which server version, and Make your project ready for the upgrade to Langfuse v4 is the step-by-step upgrade guide.
| Removed from this client | Deprecated endpoint | Replacement |
|---|---|---|
client.ingestion().batch(...) |
POST /api/public/ingestion |
OpenTelemetry ingestion β see above |
client.observations().get(...) / .getMany(...) |
GET /api/public/observations, /observations/{id} |
client.observationsV2().getMany(...) (Observations API v2) |
client.trace().get(...) / .list(...) |
GET /api/public/traces, /traces/{id} |
client.observationsV2().getMany(...) filtered by traceId (Traces) |
client.sessions().get(...) / .list(...) |
GET /api/public/sessions, /sessions/{id} |
client.observationsV2().getMany(...) filtered by sessionId (Sessions) |
client.metrics().metrics(...) |
GET /api/public/metrics |
client.metricsV2().metrics(...) (Metrics API v2) |
client.scoreV2().get(...) / .getById(...) |
GET /api/public/v2/scores, /v2/scores/{id} |
Scores API v3 β not generated yet, call GET /api/public/v3/scores directly for now |
client.datasets().getRuns(...) / .getRun(...) / .deleteRun(...) |
GET/DELETE /api/public/datasets/{name}/runs[/{runName}] |
Experiments API β not generated yet, call GET /api/public/experiments directly for now |
client.datasetRunItems().create(...) / .list(...) |
POST/GET /api/public/dataset-run-items |
Experiment Items API / OTel experiment attributes β not generated yet |
Notes:
- Score writes are unaffected.
client.score().create(...)(POST /api/public/scores) andclient.score().delete(...)stay supported after the v4 cutover. Only score reads move to v3. - Trace deletion is not deprecated.
client.trace().delete(...)andclient.trace().deleteMultiple(...)are kept; they are also how you delete experiment data now thatDELETE /datasets/{name}/runs/{runName}is gone. - Datasets themselves are not deprecated.
client.datasets()still exposes the/api/public/v2/datasetsendpoints; only the dataset run endpoints were removed. - The
/api/public/v3/scores,/api/public/experiments, and/api/public/experiment-itemsendpoints exist in the Langfuse API but are not part of this client yet. They will be picked up by the next regeneration; until then, call them directly.
Unit tests (deserialization, query string mapping) run without any credentials:
mvn testIntegration tests connect to a real Langfuse project. They require credentials and are excluded from mvn test.
-
Copy
.env.exampleto.envand fill in your API keys:cp .env.example .env
-
Ensure your Langfuse project contains the following prompts:
test-chat-promptβ chat type, at least one message withroleandcontenttest-text-promptβ text type, non-empty prompt text
-
Run all tests (unit + integration):
mvn verify
Or run only integration tests:
mvn failsafe:integration-test
Integration tests skip gracefully when credentials are absent.
Run ./mvnw release:prepare -DreleaseVersion= with the version you want to create.
Push the changes including the tag.
This project is configured to publish to Maven Central. To publish to Maven Central, you need to configure the following secrets in your GitHub repository:
OSSRH_USERNAME: Your Sonatype OSSRH usernameOSSRH_PASSWORD: Your Sonatype OSSRH passwordGPG_PRIVATE_KEY: Your GPG private key for signing artifactsGPG_PASSPHRASE: The passphrase for your GPG private key
- Ensure that langfuse-java is placed in the same directory as the main langfuse repository.
- Setup a new Java fern generator using
- name: fernapi/fern-java-sdk version: 3.38.1 output: location: local-file-system path: ../../../../langfuse-java/src/main/java/com/langfuse/client/ config: client-class-name: LangfuseClient
- Generate the new client code using
npx fern-api generate --api server. - Manually set the
packageacross all files tocom.langfuse.client. - Verify that
LangfuseClientBuilder.setAuthentication()usesBasicauth (notBearer). - Adjust Javadoc strings with HTML properties as the apidocs package does not support them.
- Re-apply the deprecated-endpoint prune. Regeneration reintroduces every endpoint marked
availability: status: deprecatedin the API definition β the ones listed under Langfuse v4: removed endpoints. Drop those resource packages and methods again, remove the now-orphaned types underresources/commons/types, and unwire them fromLangfuseClient/AsyncLangfuseClient. - Commit the changes in langfuse-java and push them to the repository.