Endpoint
POST /tasks/{task_id}/cancel
Authentication
This endpoint requires authentication via API key. Include your API key in the X-API-Key header:
X-API-Key: ca_your_api_key_here
Path Parameters
| Parameter | Type | Required | Description |
|---|
task_id | integer | Yes | Unique identifier for the task to cancel |
Request Example
curl -X POST "https://platform.chamelio.ai/tasks/12345/cancel" \
-H "X-API-Key: ca_your_api_key_here"
import requests
task_id = 12345
url = f"https://platform.chamelio.ai/tasks/{task_id}/cancel"
headers = {
"X-API-Key": "ca_your_api_key_here"
}
response = requests.post(url, headers=headers)
print(response.json())
const taskId = 12345;
const response = await fetch(
`https://platform.chamelio.ai/tasks/${taskId}/cancel`,
{
method: 'POST',
headers: {
'X-API-Key': 'ca_your_api_key_here'
}
}
);
const data = await response.json();
console.log(data);
Response
Success Response
Status Code: 200 OK
{
"task_id": 12345,
"status": "cancelled",
"message": "Task cancelled successfully"
}
Response Fields
| Field | Type | Description |
|---|
task_id | integer | ID of the cancelled task |
status | string | Updated task status (should be "cancelled") |
message | string | Success confirmation message |
Error Responses
401 Unauthorized
Returned when authentication fails. See the authentication errors section for details.
{
"detail": "Invalid API key"
}
404 Not Found
Returned when the task doesn’t exist or you don’t have access to it.
{
"detail": "Task not found"
}
409 Conflict
Returned when the task cannot be cancelled (e.g., already completed or already cancelled).
{
"detail": "Task cannot be cancelled in its current state"
}
500 Internal Server Error
Returned when cancellation fails due to a server error.
{
"detail": "Failed to cancel task"
}
Notes
Cancelling a task is irreversible. The workflow will stop at its current step and cannot be resumed.
Only tasks with status pending or in_progress can be cancelled. Completed, failed, or already cancelled tasks cannot be cancelled.
Use Cases
This endpoint is useful for:
- User-initiated cancellation - Allow users to stop workflows they no longer need
- Error handling - Cancel workflows that are stuck or encountering issues
- Workflow management - Clean up unnecessary or duplicate workflow instances
- Resource optimization - Stop workflows that are no longer relevant to free up resources