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

# Cancel Task

> Cancel a running screenplay extraction task

<Info>
  **Product**: Visual Agents
  **Use case**: Managed endpoints powering Memories.ai's open-source video search and editing agents (queries, video clipping/editing, screenplay extraction)
  **Host**: `https://mavi-backend.memories.ai/serve/api/v2`
  **Auth**: `Authorization: sk-mavi-...` (no `Bearer` prefix)
</Info>

This endpoint cancels an in-progress screenplay extraction task. Once cancelled, the task cannot be resumed.

### Code Examples

<CodeGroup>
  ```javascript fetch theme={null}
  const BASE_URL = "https://mavi-backend.memories.ai/serve/api/v2";
  const API_KEY = "sk-mavi-...";

  const taskId = "ros-sd-20260313-a3f8c2b1";
  const response = await fetch(`${BASE_URL}/screenplay/tasks/${taskId}`, {
    method: 'DELETE',
    headers: {
      'Authorization': API_KEY
    }
  });

  const data = await response.json();
  console.log(data);
  ```

  ```javascript axios theme={null}
  import axios from 'axios';

  const BASE_URL = "https://mavi-backend.memories.ai/serve/api/v2";
  const API_KEY = "sk-mavi-...";

  const taskId = "ros-sd-20260313-a3f8c2b1";
  const response = await axios.delete(`${BASE_URL}/screenplay/tasks/${taskId}`, {
    headers: {
      'Authorization': API_KEY
    }
  });

  console.log(response.data);
  ```

  ```python Python theme={null}
  import requests

  BASE_URL = "https://mavi-backend.memories.ai/serve/api/v2"
  API_KEY = "sk-mavi-..."
  HEADERS = {
      "Authorization": f"{API_KEY}"
  }

  def cancel_screenplay_task(task_id):
      url = f"{BASE_URL}/screenplay/tasks/{task_id}"
      response = requests.delete(url, headers=HEADERS)
      return response.json()

  # Usage example
  result = cancel_screenplay_task("ros-sd-20260313-a3f8c2b1")
  print(result)
  ```
</CodeGroup>

### Path Parameters

| Parameter | Type   | Required | Description                      |
| --------- | ------ | -------- | -------------------------------- |
| task\_id  | string | Yes      | The screenplay task ID to cancel |

### Response

<ResponseExample>
  ```json Response theme={null}
  {
    "code": 200,
    "msg": "success",
    "data": {
      "task_id": "ros-sd-20260313-a3f8c2b1",
      "status": "cancelled"
    },
    "failed": false,
    "success": true
  }
  ```
</ResponseExample>

### Response Parameters

| Parameter     | Type    | Description                                       |
| ------------- | ------- | ------------------------------------------------- |
| code          | integer | Response code indicating the result status        |
| msg           | string  | Response message                                  |
| data.task\_id | string  | The cancelled task ID                             |
| data.status   | string  | Task status: `"cancelled"`                        |
| success       | boolean | Indicates whether the cancellation was successful |
| failed        | boolean | Indicates whether the cancellation failed         |

### Notes

* Only tasks in `pending` or `running` status can be cancelled
* Cancellation is irreversible — a cancelled task cannot be resumed
* The processing cost charged at submission time is **not refunded** upon cancellation
* After cancellation, [Get Task Status](/visual-agents/screenplay/get-task-status) will return `"cancelled"` status


## OpenAPI

````yaml DELETE /screenplay/tasks/{task_id}
openapi: 3.1.0
info:
  title: Screenplay Extraction API
  description: APIs for screenplay extraction from short drama videos
  version: v1.0.0
servers:
  - url: https://mavi-backend.memories.ai/serve/api/v2
security:
  - ApiKeyAuth: []
paths:
  /screenplay/tasks/{task_id}:
    delete:
      summary: Cancel Task
      operationId: cancel_screenplay_task
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
            example: ros-sd-20260313-a3f8c2b1
          description: The screenplay task ID to cancel
      responses:
        '200':
          description: Task cancelled successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    example: 200
                    description: Response code indicating the result status
                  msg:
                    type: string
                    example: success
                    description: Response message
                  data:
                    type: object
                    properties:
                      task_id:
                        type: string
                        example: ros-sd-20260313-a3f8c2b1
                        description: The cancelled task ID
                      status:
                        type: string
                        example: cancelled
                        description: Task status after cancellation
                  success:
                    type: boolean
                    example: true
                    description: Indicates whether the cancellation was successful
                  failed:
                    type: boolean
                    example: false
                    description: Indicates whether the cancellation failed
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: API key for authentication

````