Skip to main content

1. Add Dependency

Maven

<dependency>
  <groupId>ai.legnext</groupId>
  <artifactId>legnext-java-sdk</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle

implementation 'ai.legnext:legnext-java-sdk:1.0.0'

2. Set API Key

Set your API key as an environment variable:
export LEGNEXT_API_KEY="your-api-key"

3. Basic Example

import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.api.ImageApi;

import java.util.HashMap;
import java.util.Map;

public class QuickStart {
    public static void main(String[] args) {
        // Configure API client
        ApiClient apiClient = Configuration.getDefaultApiClient();
        apiClient.setBasePath("https://api.legnext.ai");

        String apiKey = System.getenv("LEGNEXT_API_KEY");

        // Create API instance
        ImageApi api = new ImageApi(apiClient);

        try {
            // Generate image
            Map<String, Object> request = new HashMap<>();
            request.put("text", "a beautiful sunset over mountains");

            Object response = api.apiV1DiffusionPost(apiKey, request);

            System.out.println("Response: " + response);

        } catch (ApiException e) {
            System.err.println("Error: " + e.getMessage());
            System.err.println("Status code: " + e.getCode());
            System.err.println("Response body: " + e.getResponseBody());
        }
    }
}

4. Check Task Status

import org.openapitools.client.api.VideoApi;

VideoApi taskApi = new VideoApi(apiClient);

String jobId = "your-job-id-here";

try {
    Object taskResponse = taskApi.apiV1JobJobIdGet(jobId, apiKey);

    System.out.println("Task status: " + taskResponse);

} catch (ApiException e) {
    System.err.println("Error: " + e.getMessage());
}

Error Handling

try {
    Object response = api.apiV1DiffusionPost(apiKey, request);
} catch (ApiException e) {
    // HTTP status code
    System.err.println("Status code: " + e.getCode());

    // Error message
    System.err.println("Message: " + e.getMessage());

    // Response body
    System.err.println("Response: " + e.getResponseBody());

    // Response headers
    System.err.println("Headers: " + e.getResponseHeaders());
}

Available APIs

  • ImageApi - Text to image, variations, upscaling, editing
  • VideoApi - Video generation, upscaling, and task status
  • AccountManagementApi - Account balance and information