How to build bounded async polling for Seedance video generation in n8n

Hi everyone,

I built a reusable n8n workflow for a problem that appears with many AI video APIs: the initial request returns a task ID, while the generated video becomes available later.

A single HTTP Request node is not enough, and a naive polling loop can easily run forever, lose the task state, or hide failed generations. This workflow implements a bounded submit-and-poll pattern using standard n8n nodes.

What the workflow does

  1. Starts from a Manual Trigger and defines the model, prompt, video size, API base URL, polling interval, and maximum polling attempts.
  2. Sends a POST request to create a Seedance video generation task.
  3. Extracts and stores the returned task_id.
  4. Waits for the configured interval.
  5. Sends a GET request to retrieve the current task status.
  6. Carries the task ID and polling state through every iteration.
  7. Returns the final result_url when the task completes.
  8. Stops with a clear error when the task fails or reaches the polling limit.

The workflow follows this structure:

manualTrigger
  → setFields
  → submitTask
  → saveTaskId
  → waitInterval
  → pollTask
  → mergeResults
  → mergeState
  → completed → outputResult
  → failed    → failNode
  → timeout   → timeoutFail
  → otherwise → continuePolling → waitInterval

Why the loop is bounded

The default configuration uses:

  • intervalSeconds = 5
  • maxPolls = 120

This allows approximately 10 minutes for a generation to finish while guaranteeing that the workflow cannot poll forever.

You can adjust both values in setFields. The timeout branch checks:

poll_index >= maxPolls

A test with maxPolls = 3 confirms that the workflow sends exactly three GET requests and never sends a fourth request.

Authentication setup

Create an HTTP Header Auth credential in n8n:

Name: Authorization
Value: Bearer YOUR_VANCINE_API_KEY

Assign the same credential to both HTTP Request nodes:

  • submitTask
  • pollTask

The Code node only merges the API response with the carried loop state. It does not make network requests and does not contain an API key.

Using the workflow

  1. Download the workflow JSON from the GitHub repository.
  2. Import it into n8n.
  3. Create and assign the Header Auth credential.
  4. Update the prompt, model, size, polling interval, or maximum attempts if needed.
  5. Run the workflow manually.
  6. Read the generated video URL from outputResult.

The repository also contains tested cURL, Node.js, Python, and Postman examples:

The workflow uses standard n8n nodes, contains no embedded credentials, and was import-tested with n8n 2.30.4.

For anyone who wants to test the Seedance API path, new Vancine accounts currently receive $1 in free credit and do not require a credit card:

Disclosure: I maintain Vancine, the API used in this example. I am sharing the workflow because the bounded polling and state-carrying pattern can also be adapted to other asynchronous APIs.

Would a webhook-triggered version that sends the completed video to cloud storage be useful?

2 Likes