Video generation tasks are asynchronous. When you submit a video generation request via POST /v1/videos/generations, TokenLab returns a task identifier and enqueues the job. If a request is submitted by mistake, duplicated during a network retry, or abandoned by an end user, cancelling the task while it remains queued prevents unnecessary compute and generation charges.
This guide explains how to call the task cancellation endpoint, handle API response codes, and manage billing reservations and polling transitions.
How Task Cancellation Works
Task cancellation targets asynchronous jobs that are still queued in a pending state. Once a model worker begins generating frames (transitioning the task to processing) or the task reaches a terminal state, cancellation can no longer take place.
TokenLab supports cancellation on queued Seedance video tasks for seedance-2.0, seedance-2.0-fast, and seedance-2.5, when the task supports cancellation. For integrations using the Volcengine compatibility endpoint, see the Volc Compatible Task Cancellation reference.
Task Lifecycle States
pending: The task is enqueued and waiting for an available worker. Cancellation is supported in this window.processing: Model execution has begun. Cancellation requests will be rejected.completed: Video generation finished successfully. The result is ready.failed: The task encountered an error or was cancelled before execution.timeout: A terminal state. Stop polling atcompleted,failed, ortimeout.
Charge and Reservation Semantics
According to TokenLab's Billing and Pricing guide, some async tasks reserve the estimated cost when they are created. The final amount is recorded after the task finishes or fails:
- Reservation: When an async video task is accepted, TokenLab may hold an estimated amount based on the selected model and parameters.
- Settlement: A completed task is charged once. It carries a
billing_transaction_idthat identifies the final ledger entry. - Cancellation and Failure: A task that ends in
failed, including one cancelled while queued, is not charged. Any pending reservation is released or refunded to your workspace balance.
Because a task cancelled in the queue never completes generation, it does not produce a completed billing settlement.
Cancelling a Queued Task via API
To cancel a task, issue a DELETE request to /v1/tasks/{id} with the task ID returned during creation. For complete schema details, consult the Cancel Task API reference.
Request Example
curl -X DELETE "https://api.tokenlab.sh/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
-H "Authorization: Bearer sk-your-api-key"
Success Response (HTTP 200)
When a task is successfully cancelled before execution starts, the API responds with HTTP 200. The task status is failed, marked with cancelled: true:
{
"id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"task_id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"poll_url": "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"status": "failed",
"cancelled": true,
"cancellation_status": "cancelled",
"error": "Task cancelled before execution"
}
Error Codes and Rejection Handling
Do not assume a DELETE call always succeeds. Your application must handle these HTTP statuses:
| HTTP Status | Error Code | Meaning | Recommended Action |
|---|---|---|---|
400 |
missing_task_id, invalid_task_id |
The task ID is missing or is not a valid task ID. | Check the ID stored in your queue database. |
400 |
unsupported_task_cancel |
The model or task type does not support cancellation. | Let the task finish normally or review model support. |
403 |
task_not_owned |
The task does not belong to the workspace of this API key. | Verify workspace credentials and API key scope. |
404 |
async_task_not_found |
The task has expired or is not available. | Confirm the task ID stored in your local queue database. |
409 |
task_not_cancellable |
The task is already processing, finished, or otherwise no longer cancellable. The response field current_status gives its state. |
Accept that generation is already underway. Do not retry the delete call in a loop. |
503 |
async_task_owner_unavailable |
The task cannot be read right now. | Retry the delete call with backoff. This is the only status in the table that you retry. |
After a 503, you do not know whether the cancel took effect. Retry the DELETE. If the retry returns 409, read the task with GET /v1/tasks/{id}. A failed task with cancelled: true means that cancellation worked. A task that is processing or completed means it did not.
Polling Cancelled Tasks
When polling a task via GET /v1/tasks/{id} or the returned poll_url (as documented in the Async Jobs and Polling guide), keep the following behaviors in mind:
- HTTP 200 on Terminal Tasks: Reading the status of a failed or cancelled task returns HTTP 200. Inspect the JSON body's
statusandcancelledfields rather than relying on HTTP response codes. - Status Identification: A cancelled task displays
"status": "failed","cancelled": true, and"cancellation_status": "cancelled". The status stays readable while the public task record is retained. - Absence of Settlement IDs: Cancelled tasks do not contain a
billing_transaction_id, because no charge was settled. - Retry status reads on 503: A status read can also return
503 async_task_owner_unavailable. Retry it with backoff. Stop on401,403, and404.
import time
import requests
BASE = "https://api.tokenlab.sh/v1/tasks"
def error_code(res):
try:
return res.json().get("error", {}).get("code")
except ValueError:
return None
def cancel_task(task_id: str, api_key: str, attempts: int = 4) -> str:
"""Return "cancelled", "not_cancellable", "unavailable" or "rejected"."""
headers = {"Authorization": f"Bearer {api_key}"}
for attempt in range(attempts):
res = requests.delete(f"{BASE}/{task_id}", headers=headers, timeout=30)
if res.status_code == 200 and res.json().get("cancelled"):
return "cancelled"
if res.status_code == 503 and error_code(res) == "async_task_owner_unavailable":
time.sleep(2 ** attempt) # The task cannot be read right now. Retry with backoff.
continue
if res.status_code == 409:
return "not_cancellable" # Read GET /v1/tasks/{id} to see the final state.
return "rejected" # 400, 403 or 404: fix the request, do not retry.
return "unavailable"
def read_task(task_id: str, api_key: str) -> dict:
headers = {"Authorization": f"Bearer {api_key}"}
res = requests.get(f"{BASE}/{task_id}", headers=headers, timeout=30)
res.raise_for_status()
return res.json() # Check "status" and "cancelled", not the HTTP code.
Production Queue Integration Checklist
When integrating Seedance video workflows into worker architectures, follow these best practices:
- Persist IDs Immediately: Store both
id(ortask_id) andpoll_urlfrom thePOST /v1/videos/generationsresponse before dispatching downstream work. - Deduplicate at Submit: Prevent accidental task generation by deduplicating client-side double clicks and upstream network retries before creating tasks.
- Handle
409as Non-Fatal: If a cancellation request returns409 task_not_cancellable, treat it as an indication that processing has started. Fall back to waiting for the result and discarding output if no longer required. - Retry
503with Backoff: Treat503 async_task_owner_unavailableas temporary. Retry with a growing delay and a fixed number of attempts. - Parse the Cancellation Marker: In your polling loop, check both
status == "failed"andcancelled is Trueto distinguish user-initiated cancellations from infrastructure errors. - Reconcile Billing Using Transaction IDs: Store
billing_transaction_idonly when present on completed jobs. Do not expect transaction IDs on cancelled or failed tasks.
For additional integration patterns, review the Video Generation Guide and the Get Video Status API Reference.
Sources
- TokenLab Docs: Cancel TaskSources checked 2026-11-11
- TokenLab Docs: Cancel Task (Volc Compatible)Sources checked 2026-11-11
- TokenLab Docs: Billing and pricingSources checked 2026-11-11
- TokenLab Docs: Async jobs and pollingSources checked 2026-11-11
- TokenLab Docs: Video generationSources checked 2026-11-11
- TokenLab Docs: Get Video StatusSources checked 2026-11-11



