> ## Documentation Index
> Fetch the complete documentation index at: https://docs.legnext.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Video Generation

> Video generation API reference for Java SDK

## apiV1VideoDiffusionPost()

Generate a video from text prompt.

```java theme={null}
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.VideoApi;
import org.openapitools.client.ApiException;
import java.util.HashMap;
import java.util.Map;

ApiClient apiClient = new ApiClient();
apiClient.setBasePath("https://api.legnext.ai");
VideoApi videoApi = new VideoApi(apiClient);

String apiKey = "your-api-key-here";

// Text-to-video
Map<String, Object> body = new HashMap<>();
body.put("prompt", "a flowing river through mountains");
body.put("videoType", 1); // Optional: 0=480p, 1=720p
body.put("callback", "https://your-domain.com/webhook"); // Optional

try {
    var response = videoApi.apiV1VideoDiffusionPost(apiKey, body);
    System.out.println("Job ID: " + response.getJobId());
} catch (ApiException e) {
    System.err.println("Error: " + e.getResponseBody());
}
```

**Image-to-video animation (using jobId + imageNo):**

```java theme={null}
// Animate an existing generated image
Map<String, Object> body = new HashMap<>();
body.put("jobId", "original-image-job-id");
body.put("imageNo", 0); // Image index from original generation
body.put("videoType", 1);
body.put("callback", "https://your-domain.com/webhook"); // Optional

try {
    var response = videoApi.apiV1VideoDiffusionPost(apiKey, body);
    System.out.println("Video Job ID: " + response.getJobId());
} catch (ApiException e) {
    System.err.println("Error: " + e.getResponseBody());
}
```

**Image-to-video animation (using image URL in prompt):**

```java theme={null}
// Animate an image using URL in prompt
Map<String, Object> body = new HashMap<>();
body.put("prompt", "https://example.com/image.png a flowing river through mountains");
body.put("videoType", 1);
body.put("callback", "https://your-domain.com/webhook"); // Optional

try {
    var response = videoApi.apiV1VideoDiffusionPost(apiKey, body);
    System.out.println("Video Job ID: " + response.getJobId());
} catch (ApiException e) {
    System.err.println("Error: " + e.getResponseBody());
}
```

**Parameters:**

* Text-only mode:
  * `prompt` (String): Video prompt (1-8192 characters)
  * `videoType` (Integer, optional): Quality (0=480p, 1=720p)
  * `callback` (String, optional): Webhook URL
* jobId + imageNo mode:
  * `jobId` (String): Image generation task ID
  * `imageNo` (Integer): Image index (0-3)
  * `videoType` (Integer, optional): Quality (0=480p, 1=720p)
  * `callback` (String, optional): Webhook URL
* Image URL in prompt mode:
  * `prompt` (String): "\[image\_url] prompt text" format (1-8192 characters)
  * `videoType` (Integer, optional): Quality (0=480p, 1=720p)
  * `callback` (String, optional): Webhook URL

**Returns:** Response with `job_id` and `status`

***

## apiV1ExtendVideoPost()

Extend an existing video.

```java theme={null}
Map<String, Object> body = new HashMap<>();
body.put("jobId", "original-video-job-id");
body.put("videoNo", 0); // 0-3
body.put("prompt", "continue with dramatic lighting"); // Optional
body.put("callback", "https://your-domain.com/webhook"); // Optional

try {
    var response = videoApi.apiV1ExtendVideoPost(apiKey, body);
    System.out.println("Extended video Job ID: " + response.getJobId());
} catch (ApiException e) {
    System.err.println("Error: " + e.getResponseBody());
}
```

**Parameters:**

* `jobId` (String): Original video task ID
* `videoNo` (Integer): Video index (0-3)
* `prompt` (String, optional): Extension prompt (1-8192 characters)
* `callback` (String, optional): Webhook URL

***

## apiV1VideoUpscalePost()

Upscale video to higher resolution.

```java theme={null}
Map<String, Object> body = new HashMap<>();
body.put("jobId", "original-video-job-id");
body.put("videoNo", 0); // 0-3
body.put("callback", "https://your-domain.com/webhook"); // Optional

try {
    var response = videoApi.apiV1VideoUpscalePost(apiKey, body);
    System.out.println("Upscaled video Job ID: " + response.getJobId());
} catch (ApiException e) {
    System.err.println("Error: " + e.getResponseBody());
}
```

**Parameters:**

* `jobId` (String): Original video task ID
* `videoNo` (Integer): Video index (0-3)
* `callback` (String, optional): Webhook URL

***

## Complete Example

```java theme={null}
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.VideoApi;
import org.openapitools.client.ApiException;
import java.util.HashMap;
import java.util.Map;

public class VideoGenerationExample {
    public static void main(String[] args) {
        ApiClient apiClient = new ApiClient();
        apiClient.setBasePath("https://api.legnext.ai");
        VideoApi videoApi = new VideoApi(apiClient);

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

        try {
            // Step 1: Generate initial video
            Map<String, Object> body = new HashMap<>();
            body.put("prompt", "a sunset over ocean waves");
            body.put("videoType", 1);

            var initialResponse = videoApi.apiV1VideoDiffusionPost(apiKey, body);
            String jobId = initialResponse.getJobId();
            System.out.println("Initial video job: " + jobId);

            // Wait for completion (see task-management.mdx)
            // ...

            // Step 2: Extend the video
            Map<String, Object> extendBody = new HashMap<>();
            extendBody.put("jobId", jobId);
            extendBody.put("videoNo", 0);
            extendBody.put("prompt", "zoom in on the waves");

            var extendResponse = videoApi.apiV1ExtendVideoPost(apiKey, extendBody);
            System.out.println("Extended video job: " + extendResponse.getJobId());

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

***

## Next Steps

* [Image Generation](/sdk/java/image-generation)
* [Task Management](/sdk/java/task-management)
* [Quick Start](/sdk/java/quickstart)
