TokenLab

Async Jobs

Cancel Task

Cancel a queued async task when the provider and model support cancellation

DELETE
/v1/tasks/{id}

Overview

Use DELETE /v1/tasks/{id} to cancel an asynchronous task that has not started running yet. Use the same task ID from the create response or the returned poll_url.

Supported Tasks

Cancellation is available for queued Seedance tasks using seedance-1.5-pro, seedance-2.0, seedance-2.0-fast, or seedance-2.5 when that task supports cancellation. A task already running or in a terminal state cannot be cancelled. Status remains queryable while its public task record is retained.

Path Parameters

idstringpathrequired

The async task ID returned by the create request or embedded in poll_url.

Response

idstring

Canonical async task identifier.

task_idstring

Async task identifier alias.

poll_urlstring

Preferred polling URL for the task. It remains valid after cancellation.

statusstring

Task status. A successfully cancelled task is returned as failed with cancelled: true for compatibility with existing status values.

cancelledboolean

true when the task was cancelled before execution.

cancellation_statusstring

Cancellation marker. The value is cancelled when cancellation succeeds.

errorstring

Cancellation reason or task failure message.

Error Behavior

400 unsupported_task_cancel means the task type, provider, or model does not support cancellation. 409 task_not_cancellable means the task is already processing, terminal, or otherwise no longer cancellable. 403 means the API key cannot access the task.

Example

Request

cURL
curl -X DELETE "https://api.tokenlab.sh/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
  -H "Authorization: Bearer sk-your-api-key"
Response
{
  "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"
}
{  "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"}

Authorization

BearerAuth
AuthorizationBearer <token>

API Key authentication. Create or manage API keys in Dashboard > API > API Keys.

In: header

Path Parameters

id*string

The async task ID returned by id / task_id, or embedded in poll_url

Response

application/json

application/json

application/json

application/json

application/json

application/json

application/json