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.
We recommend to solve tracing via the OpenTelemetry Instrumentation instead of using the Ingestion API directly. This allows for a more detailed and standardized tracing experience without the need to handle batching and updates internally. Check out our Spring AI Example for more details.
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.0.6</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();
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.getBody());
System.out.println(error.getStatusCode());
}
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: 2.20.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
package
across all files tocom.langfuse.client
. - Overwrite
this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + encodedToken);
toBasic
in LangfuseClientBuilder.java. - Commit the changes in langfuse-java and push them to the repository.