> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Task

> Delete a task and its associated data

Delete a task by ID. Running tasks will be cancelled before deletion, and all associated data including results and conversation history will be permanently removed.

## Path Parameters

<ParamField path="task_id" type="string" required>
  Unique identifier of the task to delete (UUID format)
</ParamField>

## Response

Returns `204 No Content` on successful deletion (empty response body).

## Example Request

```bash theme={"dark"}
curl -X DELETE -H "x-api-key: <your-api-key>" \
  "https://api.xpander.ai/v1/tasks/<task-id>"
```

## Response Status Codes

| Status | Meaning                                            |
| ------ | -------------------------------------------------- |
| 204    | Task deleted successfully                          |
| 404    | Task not found                                     |
| 401    | Unauthorized (invalid API key)                     |
| 403    | Forbidden (task belongs to different organization) |

## Important Notes

* **Permanent deletion** - This action cannot be undone
* **Running tasks** - Will be cancelled before deletion
* **Data removal** - Results, conversation history, and all associated data are removed
* **Sub-tasks** - All sub-tasks are also deleted

## Example with Error Handling

```bash theme={"dark"}
TASK_ID="<task-id>"

RESPONSE=$(curl -w "\n%{http_code}" -X DELETE \
  -H "x-api-key: <your-api-key>" \
  "https://api.xpander.ai/v1/tasks/$TASK_ID")

HTTP_CODE=$(echo "$RESPONSE" | tail -n1)

if [[ $HTTP_CODE == "204" ]]; then
  echo "Task deleted successfully"
elif [[ $HTTP_CODE == "404" ]]; then
  echo "Task not found"
else
  echo "Error: $HTTP_CODE"
fi
```

## Use Cases

* **Clean up completed tasks** - Remove old task data to save storage
* **Cancel running tasks** - Stop a task that's in progress
* **Manage sensitive data** - Delete tasks containing sensitive information
* **Maintain organization** - Remove test or failed tasks


## OpenAPI

````yaml DELETE /v1/tasks/{task_id}
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/tasks/{task_id}:
    delete:
      tags:
        - API v1
        - Tasks
        - Tasks CRUD
      summary: Delete Task
      description: Delete Task by ID
      operationId: Delete_Task_v1_tasks__task_id__delete
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
            title: Task Id
      responses:
        '204':
          description: Successful Response
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````