Skip to main content
DELETE
/
api
/
v1
/
tasks
/
{id}
Cancel Task
curl --request DELETE \
  --url https://api.example.com/api/v1/tasks/{id}

Documentation Index

Fetch the complete documentation index at: https://docs.sigmic.ai/llms.txt

Use this file to discover all available pages before exploring further.

Cancel 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

ParameterTypeDescription
idstringThe 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"

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 be cancelled:
{
  "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

CodeDescription
AUTH_REQUIREDNo authentication provided
INVALID_API_KEYInvalid or expired API key
NOT_FOUNDTask with the specified ID was not found