Package com.langfuse.client
Class LangfuseClientBuilder
java.lang.Object
com.langfuse.client.LangfuseClientBuilder
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd a custom header to be sent with all requests.build()protected ClientOptionscredentials(String username, String password) httpClient(okhttp3.OkHttpClient httpClient) Sets the underlying OkHttp clientmaxRetries(int maxRetries) Sets the maximum number of retries for the client.protected voidsetAdditional(ClientOptions.Builder builder) Override this method to add any additional configuration to the client.protected voidsetAuthentication(ClientOptions.Builder builder) Override this method to customize authentication.protected voidsetCustomHeaders(ClientOptions.Builder builder) Override this method to add or modify custom headers.protected voidsetEnvironment(ClientOptions.Builder builder) Sets the environment configuration for the client.protected voidsetHttpClient(ClientOptions.Builder builder) Sets the OkHttp client configuration.protected voidsetRetries(ClientOptions.Builder builder) Sets the retry configuration for failed requests.protected voidsetTimeouts(ClientOptions.Builder builder) Sets the request timeout configuration.timeout(int timeout) Sets the timeout (in seconds) for the client.protected voidOverride this method to add custom validation logic before the client is built.xLangfusePublicKey(String xLangfusePublicKey) Sets xLangfusePublicKeyxLangfuseSdkName(String xLangfuseSdkName) Sets xLangfuseSdkNamexLangfuseSdkVersion(String xLangfuseSdkVersion) Sets xLangfuseSdkVersion
-
Constructor Details
-
LangfuseClientBuilder
public LangfuseClientBuilder()
-
-
Method Details
-
credentials
-
xLangfuseSdkName
Sets xLangfuseSdkName -
xLangfuseSdkVersion
Sets xLangfuseSdkVersion -
xLangfusePublicKey
Sets xLangfusePublicKey -
url
-
timeout
Sets the timeout (in seconds) for the client. Defaults to 60 seconds. -
maxRetries
Sets the maximum number of retries for the client. Defaults to 2 retries. -
httpClient
Sets the underlying OkHttp client -
addHeader
Add a custom header to be sent with all requests. For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead.- Parameters:
name- The header namevalue- The header value- Returns:
- This builder for method chaining
-
buildClientOptions
-
setEnvironment
Sets the environment configuration for the client. Override this method to modify URLs or add environment-specific logic.- Parameters:
builder- The ClientOptions.Builder to configure
-
setAuthentication
Override this method to customize authentication. This method is called during client options construction to set up authentication headers.- Parameters:
builder- The ClientOptions.Builder to configure Example:@Override protected void setAuthentication(ClientOptions.Builder builder) { super.setAuthentication(builder); // Keep existing auth builder.addHeader("X-API-Key", this.apiKey); }
-
setCustomHeaders
Override this method to add or modify custom headers. This method is called during client options construction to set up custom headers defined in the API.- Parameters:
builder- The ClientOptions.Builder to configure Example:@Override protected void setCustomHeaders(ClientOptions.Builder builder) { super.setCustomHeaders(builder); // Keep existing headers builder.addHeader("X-Trace-ID", generateTraceId()); }
-
setTimeouts
Sets the request timeout configuration. Override this method to customize timeout behavior.- Parameters:
builder- The ClientOptions.Builder to configure
-
setRetries
Sets the retry configuration for failed requests. Override this method to implement custom retry strategies.- Parameters:
builder- The ClientOptions.Builder to configure
-
setHttpClient
Sets the OkHttp client configuration. Override this method to customize HTTP client behavior (interceptors, connection pools, etc).- Parameters:
builder- The ClientOptions.Builder to configure
-
setAdditional
Override this method to add any additional configuration to the client. This method is called at the end of the configuration chain, allowing you to add custom headers, modify settings, or perform any other client customization.- Parameters:
builder- The ClientOptions.Builder to configure Example:@Override protected void setAdditional(ClientOptions.Builder builder) { builder.addHeader("X-Request-ID", () -> UUID.randomUUID().toString()); builder.addHeader("X-Client-Version", "1.0.0"); }
-
validateConfiguration
protected void validateConfiguration()Override this method to add custom validation logic before the client is built. This method is called at the beginning of the build() method to ensure the configuration is valid. Throw an exception to prevent client creation if validation fails. Example:@Override protected void validateConfiguration() { super.validateConfiguration(); // Run parent validations if (tenantId == null || tenantId.isEmpty()) { throw new IllegalStateException("tenantId is required"); } } -
build
-