# LINGTU AI AI media generation workflow

Use this workflow to create an AI image or video task once, poll the same schedule, and retrieve the generated asset without accidentally creating duplicates.

## Operations

- Create: [createAiGenerationSchedule](/openapi/operations/createAiGenerationSchedule.md)
- Poll: [listAiTasksByScheduleId](/openapi/operations/listAiTasksByScheduleId.md)

## Sequence

1. Call `POST /v1/ai/schedule/create` with exactly one image or video request body.
2. Persist `data.scheduleId` from the successful response.
3. Poll `GET /v1/ai/task/listByScheduleId?scheduleId=...` about every five seconds.
4. Continue polling while any task is `WAITING_SUBMIT`, `SUBMITTING`, `PENDING`, or `PROCESSING`.
5. Stop successfully when every requested task is `COMPLETED`.
6. Stop with an explicit failure when a task is `SUBMIT_FAILED`, `FAILED`, `CANCELLED`, or `EXPIRED`.
7. For video tasks, prefer `customResult.videoUrl`, then `result.url`. For image tasks, prefer `result.url`, then `resultUrl`.

## Idempotency and retry safety

- A network error or stopped polling process does not mean the generation task failed.
- Resume polling with the saved `scheduleId` after interruptions.
- Do not create a second schedule unless the original task reached an explicit terminal failure and your application decided to retry.
- Retry HTTP 408, 429, and transient 5xx responses with exponential backoff. Respect `Retry-After` when present.
