WaveSpeedAI

How Do I Handle Wan 3.0 Failed Generations?

Handle Wan 3.0 failures with stored job states, clear retry rules, cost reconciliation, and user-facing explanations.

By Dora5 min read
How Do I Handle Wan 3.0 Failed Generations?

Overview

Handle Wan 3.0 failed generations as normal product states, not as invisible backend exceptions. Save the request, prediction id, route, settings, status, error response, cost record, retry decision, and support note for every failed job.

Separate failure types before retrying. A malformed prompt, missing file, blocked content, expired asset URL, provider timeout, and user cancellation should not follow the same path. Some failures deserve a corrected input; others need backoff, support escalation, or a clear no-retry message to the user.

Cost handling must be explicit. Store the pre-submit estimate and the final prediction charge so billing questions can be answered from records, not memory. If your product grants retries or refunds, make that rule visible before the user starts high-resolution or long-duration work.

WaveSpeedAI’s Wan 3.0 route uses asynchronous statuses, which lets your app display pending, running, completed, failed, cancelled, timeout, and deleted states cleanly. Build UI copy for each state before launch. A good failure flow keeps trust even when a generation does not produce a usable clip. It also prevents support from guessing what happened later.

For the retry decision, I would make the first branch explicit:

What happenedNext action
400 or an invalid inputCorrect the prompt, file, URL, or parameter before creating a new request.
401 or 403Fix the API key or account permissions. Do not retry unchanged.
429 on a result checkHonor Retry-After when present, then poll again with backoff.
A dropped connection or 5xx on the submit POSTDo not submit again automatically. The task may already exist. Check recent predictions and reconcile the attempt first.
failed, cancelled, timeout, or deleted in a result responseStop polling, retain the task ID and error, then decide whether a new attempt is appropriate.

That POST/GET distinction matters. A client timeout does not prove that generation failed, and a second submit can create a second task. WaveSpeed’s retry guidance documents this boundary. In the provider response, created and processing are task statuses; “pending” and “running” can remain your app’s display labels.

Here is a small Python pattern for one text-to-video request. The local request_key prevents this script from submitting the same user request twice; it is not a claim that the WaveSpeed API accepts an idempotency key. Install requests, set WAVESPEED_API_KEY and a stable WAN_REQUEST_KEY, and review the model inputs before running it. The example has not been used to place a paid generation.

import json
import os
import sqlite3
import time

import requests

api = "https://api.wavespeed.ai/api/v3"
key = os.environ["WAVESPEED_API_KEY"]
request_key = os.environ["WAN_REQUEST_KEY"]
headers = {"Authorization": f"Bearer {key}"}

payload = {
    "prompt": "A ceramic mug on a wooden desk, steady camera, soft morning light",
    "resolution": "720p",
    "aspect_ratio": "16:9",
    "duration": 5,
}
payload_text = json.dumps(payload, sort_keys=True)

db = sqlite3.connect("wan_jobs.sqlite3")
db.execute(
    "CREATE TABLE IF NOT EXISTS jobs "
    "(request_key TEXT PRIMARY KEY, payload TEXT NOT NULL, task_id TEXT)"
)
claim = db.execute(
    "INSERT OR IGNORE INTO jobs VALUES (?, ?, NULL)",
    (request_key, payload_text),
)
db.commit()  # Persist the claim before sending a billable POST.

saved_payload, task_id = db.execute(
    "SELECT payload, task_id FROM jobs WHERE request_key = ?",
    (request_key,),
).fetchone()

if saved_payload != payload_text:
    raise RuntimeError("This request key belongs to different inputs.")

if claim.rowcount == 1:
    try:
        response = requests.post(
            f"{api}/alibaba/wan-3.0/text-to-video",
            headers=headers,
            json=payload,
            timeout=(10, 60),
        )
    except requests.RequestException as exc:
        raise RuntimeError(
            "Submit outcome unknown. Check recent predictions before another POST."
        ) from exc

    if response.status_code != 200:
        raise RuntimeError(
            f"Submit returned {response.status_code}. Save the response and "
            "reconcile the attempt before submitting again: " + response.text
        )

    body = response.json()
    task_id = (body.get("data") or {}).get("id")
    if body.get("code") != 200 or not task_id:
        raise RuntimeError(
            "No confirmed task ID. Reconcile recent predictions before another POST."
        )

    db.execute(
        "UPDATE jobs SET task_id = ? WHERE request_key = ?",
        (task_id, request_key),
    )
    db.commit()
elif not task_id:
    raise RuntimeError(
        "An earlier submit has no saved task ID. Reconcile it before another POST."
    )

delay = 2
while True:
    try:
        response = requests.get(
            f"{api}/predictions/{task_id}/result",
            headers=headers,
            timeout=(10, 30),
        )
        if response.status_code in {429, 500, 502, 503, 504}:
            retry_after = response.headers.get("Retry-After", "")
            wait = int(retry_after) if retry_after.isdecimal() else delay
            time.sleep(max(2, wait))
            delay = min(delay * 2, 60)
            continue
        response.raise_for_status()
        body = response.json()
        if body.get("code") != 200:
            raise RuntimeError(body)
        result = body["data"]
    except (requests.Timeout, requests.ConnectionError):
        time.sleep(delay)
        delay = min(delay * 2, 60)
        continue

    delay = 2
    status = result.get("status")
    if status in {"completed", "failed", "cancelled", "timeout", "deleted"}:
        print(json.dumps({"task_id": task_id, "result": result}, indent=2))
        break
    time.sleep(2)

billing_key = os.getenv("WAVESPEED_BILLING_API_KEY")
if billing_key:
    bill = requests.post(
        f"{api}/billings/search",
        headers={"Authorization": f"Bearer {billing_key}"},
        json={"prediction_uuids": [task_id], "page": 1, "page_size": 10},
        timeout=(10, 60),
    )
    bill.raise_for_status()
    print(json.dumps(bill.json()["data"]["items"], indent=2))
else:
    print(f"Check the billing dashboard for task {task_id}.")

A billing record may appear shortly after the task finishes, so an empty immediate search is a reason to check again, not to regenerate the video. For team organizations, the billing search endpoint requires a key from an Owner, Admin, or Billing member. Keep charges and any reversal records alongside the task ID. For the request-and-attempt record behind this pattern, see how to retry a video generation job without duplicates.

Source: WaveSpeedAI Wan 3.0 API collection; Alibaba Cloud Wan3.0 API reference. Source check: 2026-11-20.


Previous posts:

Share