Java SDK DocumentationEnterprise-ready Java integration
Complete documentation for integrating Litends AI services into your Java applications with thread-safe operations and enterprise features.
Java Guide
Installation
Get started with the Java SDK
Java SDK Installation
Install the Litends AI Java SDK using Maven or Gradle. The SDK supports Java 8+ and provides comprehensive integration with our AI services.
<dependency>
<groupId>com.litends</groupId>
<artifactId>litends-java-sdk</artifactId>
<version>1.0.0</version>
</dependency>
Requirements
- • Java 8 or higher
- • Maven or Gradle build tool
- • Internet connection for dependencies
- • Valid Litends AI API key
Getting Your API Key
- Log into your Litends dashboard
- Navigate to "API Keys" section
- Click "Generate New Key"
- Copy and securely store your key
- Never share your API key publicly
Quick Start
Your first API call in minutes
Getting Started with Java SDK
Get up and running with the Java SDK in minutes. Initialize the client and make your first API call.
import com.litends.sdk.LitendsClient;
LitendsClient client = new LitendsClient.Builder()
.apiKey("your-api-key")
.build();
Your First Prediction
import com.litends.models.PredictionRequest;
import com.litends.models.PredictionResponse;
// Create prediction request
PredictionRequest request = new PredictionRequest.Builder()
.setModelId("sales-forecast-v1")
.addFeature("revenue", 50000.0)
.addFeature("quarter", "Q2")
.addFeature("region", "north-america")
.build();
// Make prediction
try {
PredictionResponse response = client.predictions().create(request);
System.out.println("Prediction: " + response.getPrediction());
System.out.println("Confidence: " + response.getConfidence());
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
Configuration
Advanced client configuration
Advanced Configuration
Configure the SDK with custom settings for timeouts, retries, logging, and connection pooling.
import com.litends.sdk.LitendsClient;
import com.litends.sdk.config.ClientConfig;
import java.time.Duration;
ClientConfig config = new ClientConfig.Builder()
.timeout(Duration.ofSeconds(30))
.maxRetries(3)
.retryDelay(Duration.ofSeconds(1))
.enableLogging(true)
.maxConnections(50)
.build();
LitendsClient client = new LitendsClient.Builder()
.apiKey(System.getenv("LITENDS_API_KEY"))
.config(config)
.build();
Configuration Options
- • Timeout: Request timeout duration
- • Retries: Maximum retry attempts
- • Retry Delay: Delay between retries
- • Logging: Enable/disable request logging
- • Connections: Max connection pool size
Environment Variables
- •
LITENDS_API_KEY
- Your API key - •
LITENDS_BASE_URL
- Custom API base URL - •
LITENDS_TIMEOUT
- Request timeout - •
LITENDS_DEBUG
- Enable debug logging
Advanced Examples
Complex implementation patterns
Batch Processing & Error Handling
Process multiple predictions and handle errors gracefully with comprehensive exception handling.
import com.litends.models.BatchPredictionRequest;
import com.litends.models.BatchPredictionResponse;
import com.litends.exceptions.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
// Create batch prediction request
List<Map<String, Object>> features = Arrays.asList(
Map.of("revenue", 45000.0, "quarter", "Q3", "region", "europe"),
Map.of("revenue", 62000.0, "quarter", "Q4", "region", "asia"),
Map.of("revenue", 38000.0, "quarter", "Q1", "region", "americas")
);
BatchPredictionRequest batchRequest = new BatchPredictionRequest.Builder()
.setModelId("sales-forecast-v2")
.setFeatures(features)
.build();
// Process batch predictions with error handling
try {
BatchPredictionResponse batchResponse = client.predictions().createBatch(batchRequest);
for (int i = 0; i < batchResponse.getPredictions().size(); i++) {
System.out.println("Prediction " + (i + 1) + ": " +
batchResponse.getPredictions().get(i).getPrediction());
}
} catch (AuthenticationException e) {
System.err.println("Authentication failed: " + e.getMessage());
} catch (RateLimitException e) {
System.err.println("Rate limit exceeded. Retry after: " + e.getRetryAfter());
} catch (ValidationException e) {
System.err.println("Invalid request: " + e.getMessage());
} catch (ApiException e) {
System.err.println("API error: " + e.getMessage());
}
Async Operations
Handle asynchronous API calls with CompletableFuture:
CompletableFuture<PredictionResponse> future =
client.predictions().createAsync(request);
future.thenAccept(response -> {
System.out.println("Prediction: " +
response.getPrediction());
}).exceptionally(throwable -> {
System.err.println("Error: " +
throwable.getMessage());
return null;
});
Connection Pooling
Configure connection pooling for high performance:
ConnectionPool pool = new ConnectionPool.Builder()
.maxConnections(100)
.keepAliveTimeout(Duration.ofMinutes(5))
.connectionTimeout(Duration.ofSeconds(10))
.build();
LitendsClient client = new LitendsClient.Builder()
.apiKey("your-api-key")
.connectionPool(pool)
.build();
Ready to integrate our API?
Get your API key and start building powerful AI applications with our Java SDK.