Cancel Task
curl --request DELETE \
--url https://api.example.com/api/v1/tasks/{id}import requests
url = "https://api.example.com/api/v1/tasks/{id}"
response = requests.delete(url)
print(response.text)const options = {method: 'DELETE'};
fetch('https://api.example.com/api/v1/tasks/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/tasks/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/tasks/{id}"
req, _ := http.NewRequest("DELETE", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.delete("https://api.example.com/api/v1/tasks/{id}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/tasks/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
response = http.request(request)
puts response.read_bodyTask API
Cancel Task
Cancel a running task
DELETE
/
api
/
v1
/
tasks
/
{id}
Cancel Task
curl --request DELETE \
--url https://api.example.com/api/v1/tasks/{id}import requests
url = "https://api.example.com/api/v1/tasks/{id}"
response = requests.delete(url)
print(response.text)const options = {method: 'DELETE'};
fetch('https://api.example.com/api/v1/tasks/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/tasks/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/tasks/{id}"
req, _ := http.NewRequest("DELETE", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.delete("https://api.example.com/api/v1/tasks/{id}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/tasks/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
response = http.request(request)
puts response.read_bodyCancel Task
Cancel a running or pending task. This terminates the task execution and releases associated resources.Request
DELETE /api/v1/tasks/{id}
Authorization: Bearer {api_key}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The unique task identifier |
Response
{
"success": true,
"data": {
"message": "Task cancelled"
}
}
Examples
curl -X DELETE https://api.sigmic.ai/api/v1/tasks/c37c1d78-4d23-4e53-949a-ddd775f25e01 \
-H "Authorization: Bearer sigmic_your_key_here"
const taskId = 'c37c1d78-4d23-4e53-949a-ddd775f25e01';
const response = await fetch(
`https://api.sigmic.ai/api/v1/tasks/${taskId}`,
{
method: 'DELETE',
headers: {
'Authorization': 'Bearer sigmic_your_key_here'
}
}
);
const result = await response.json();
console.log(result.data.message); // "Task cancelled"
import requests
task_id = 'c37c1d78-4d23-4e53-949a-ddd775f25e01'
response = requests.delete(
f'https://api.sigmic.ai/api/v1/tasks/{task_id}',
headers={'Authorization': 'Bearer sigmic_your_key_here'}
)
result = response.json()
print(result['data']['message']) # "Task cancelled"
Use Cases
Timeout Handling
Cancel tasks that take too long:const API_KEY = 'sigmic_your_key_here';
const BASE_URL = 'https://api.sigmic.ai';
async function createTaskWithTimeout(message, timeoutMs = 60000) {
// 1. Create the task (returns JSON immediately)
const formData = new FormData();
formData.append('message', message);
const createResponse = await fetch(`${BASE_URL}/api/v1/tasks`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}` },
body: formData
});
const { data: { id: taskId } } = await createResponse.json();
// 2. Set up timeout to cancel
const timeoutId = setTimeout(async () => {
await fetch(`${BASE_URL}/api/v1/tasks/${taskId}`, {
method: 'DELETE',
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
console.log('Task cancelled due to timeout');
}, timeoutMs);
// 3. Stream the execution
const streamResponse = await fetch(`${BASE_URL}/api/v1/tasks/${taskId}/stream`, {
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const reader = streamResponse.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const events = buffer.split('\n\n');
buffer = events.pop() || '';
for (const event of events) {
if (!event.trim() || event.startsWith(':')) continue;
const lines = event.split('\n');
const eventType = lines[0]?.replace('event: ', '');
const dataLine = lines[1]?.replace('data: ', '');
if (!dataLine) continue;
const data = JSON.parse(dataLine);
if (eventType === 'content') {
process.stdout.write(data.text);
}
if (eventType === 'done') {
console.log('\nTask completed');
}
}
}
clearTimeout(timeoutId);
}
User-Initiated Cancellation
const API_KEY = 'sigmic_your_key_here';
const BASE_URL = 'https://api.sigmic.ai';
let currentTaskId = null;
// Start a task (fire-and-forget)
async function startTask(message) {
const formData = new FormData();
formData.append('message', message);
const response = await fetch(`${BASE_URL}/api/v1/tasks`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}` },
body: formData
});
const { data: { id: taskId } } = await response.json();
currentTaskId = taskId;
// Connect to stream in background
// ... processSSEStream(taskId, handlers)
}
// Cancel button handler
async function onCancelClick() {
if (currentTaskId) {
await fetch(`${BASE_URL}/api/v1/tasks/${currentTaskId}`, {
method: 'DELETE',
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
currentTaskId = null;
console.log('Task cancelled by user');
}
}
Task Status After Cancellation
After cancellation, the task’s status will becancelled:
{
"success": true,
"data": {
"id": "c37c1d78-4d23-4e53-949a-ddd775f25e01",
"status": "cancelled",
"error": null,
"completedAt": "2026-01-26T16:00:00.000Z"
}
}
Important Notes
Cancelling a task terminates its session. You cannot send follow-up messages to a cancelled task.
If a tool is currently executing when you cancel, it may complete before the cancellation takes effect. The task will still be marked as cancelled.
Errors
| Code | Description |
|---|---|
AUTH_REQUIRED | No authentication provided |
INVALID_API_KEY | Invalid or expired API key |
NOT_FOUND | Task with the specified ID was not found |