Endpoint
Authentication
This endpoint requires API key authentication via theAuthorization header:
Path Parameters
string
required
The unique identifier of the task to cancel
Requirements
- Task must have status
Starting - Tasks that are already
Processing,Succeeded,Failed, orCancelledcannot be cancelled
Response
On success, returns a plain text response:Status Codes
- 200: Task cancelled successfully
- 400: Bad request (task cannot be cancelled due to invalid status)
- 404: Task not found or expired
- 500: Internal server error
Behavior
Depending on the task state:- For new tasks: Status will be updated to
Cancelledand processing will never begin - For updating tasks: Task will revert to its previous state before the update was requested
Examples
Use Cases
- Accidental Submissions: Cancel tasks that were created by mistake
- Configuration Errors: Cancel and recreate tasks with corrected settings
- Queue Management: Cancel low-priority tasks during high-load periods
- Testing: Cancel test tasks that are no longer needed
Timing Window
Tasks can only be cancelled while they’re in theStarting state, which is typically:
- Right after task creation
- Before worker processes pick up the task
- During the queue waiting period
Processing state, it cannot be cancelled and must complete or fail naturally.
After Cancellation
Once a task is cancelled:- Status changes to
Cancelled - Message is updated to “Task cancelled”
- Task will never begin processing
- Task can be deleted to free up resources
- Task cannot be restarted - you must create a new task instead
Error Messages
The task ID doesn’t exist, has expired, or you don’t have access to it
The task is not in
Starting state. Common reasons:- Task is already
Processing - Task has
SucceededorFailed - Task was already
Cancelled
Best Practices
-
Check Status First: Verify the task is in
Startingstate before attempting to cancel -
Quick Action: Cancel as soon as you realize the task is not needed, as tasks may move to
Processingquickly - Create New Tasks: After cancelling, create a new task with correct settings rather than trying to uncancelled
- Clean Up: Consider deleting cancelled tasks to keep your task list clean
Advanced Example: Cancel and Recreate
Related Endpoints
- Delete Task - Permanently delete a
Succeeded,Failed, orCancelledtask - Get Task - Check task status before cancelling
- Create Task - Create a new task to replace the cancelled one