API v1

Task status and results

What the task states mean, polling or callbacks, downloading results and cancelling tasks.

View Markdown
On this page

After you create a task, read its progress and result by task ID, or wait for a callback.

Task status

While a task is processing, phase names the current stage: preparing inputs, waiting, starting, generating, confirming the result, finishing and awaiting settlement. Every value is on Statuses and reasons.

Three status fields

FieldMeaning
statusTask execution; the final states are succeeded, failed and cancelled.
delivery_statusDelivery of the result files; download them once it is available.
settlement_statusBilling settlement; the charge is final once it is settled.

Poll

Read the task every few seconds until status is final:

curl --request GET "${CHENVOYA_BASE_URL}/v1/video/tasks/${TASK_ID}" \
  --header "Authorization: Bearer ${CHENVOYA_API_KEY}"

Callbacks

After you register and verify a callback address in the console, pass callback_url when you create a task and you receive task.completed when it finishes. The event has no download link: read the task once more. See Receive callbacks.

Download the result

A succeeded task lists its result files in output.assets with role result. url is an HTTPS download link; each task read signs a fresh one that works for up to 24 hours and never after expires_at (7 days after the result is ready by default); when it has expired or is not available, url is null and download_status says why. Save the file to your own storage in time.

curl --output video.mp4 "$VIDEO_URL"

List tasks

GET /v1/video/tasks lists all of your team's tasks, whichever API key created them, newest first. A list entry holds the IDs, model, statuses and times; read usage, charges, results and errors from the task by its ID.

curl --request GET "${CHENVOYA_BASE_URL}/v1/video/tasks" \
  --header "Authorization: Bearer ${CHENVOYA_API_KEY}"

Cancel a task

POST /v1/video/tasks/{task_id}/cancel needs an Idempotency-Key and no body.

  • Before generation starts, cancellation takes effect at once: the answer is effective, the task becomes cancelled and the whole reservation is released.
  • After generation starts, the answer is not_effective with reason generation_already_started; the task continues and is settled as usual.
  • A finished task without a cancellation returns 409 task_not_cancellable.
IDEMPOTENCY_KEY=${IDEMPOTENCY_KEY:-$(uuidgen)}
printf '%s\n' "Save IDEMPOTENCY_KEY for retries: ${IDEMPOTENCY_KEY}" >&2
curl --request POST "${CHENVOYA_BASE_URL}/v1/video/tasks/${TASK_ID}/cancel" \
  --header "Authorization: Bearer ${CHENVOYA_API_KEY}" \
  --header "Idempotency-Key: ${IDEMPOTENCY_KEY}"

Failure reasons

A failed task gives its reason in error.code, such as input_fetch_failed when an input could not be downloaded or generation_failed. Every value is on Statuses and reasons. Failed and cancelled tasks are settled at no charge.

Next steps