Skip to main content

Understanding Async Operations

All image and video generation operations in the Legnext API are asynchronous. When you submit a request, you receive a job_id that you use to check the status and retrieve results.

Setup

Checking Task Status

Check the status of a job:

Polling for Completion

Poll a task until it completes:

Complete Example

Generate an image and wait for completion:

Error Handling

Handle errors during task polling:

Best Practices

  1. Polling Interval: Use 5-10 second intervals to avoid rate limiting
  2. Timeout: Set a reasonable maximum wait time (5-10 minutes)
  3. Error Handling: Always check for “failed” status
  4. Cancellation: Support CancellationToken for long-running operations

Next Steps