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

# Cancel task

> Cancel a running task and associated jobs.

Cancels the task and marks it as `CANCELLED`.


## OpenAPI

````yaml /openapi.json POST /tasks/{taskIdOrSlug}/cancel
openapi: 3.0.3
info:
  title: Twill API
  version: 1.0.0
  description: Programmatically create and manage Twill tasks via REST API.
servers:
  - url: https://twill.ai/api/v1
security:
  - bearerAuth: []
tags:
  - name: Tasks
    description: Create and manage tasks.
paths:
  /tasks/{taskIdOrSlug}/cancel:
    post:
      tags:
        - Tasks
      summary: Cancel task
      description: Cancel a running task and all associated jobs.
      operationId: cancelTask
      parameters:
        - name: taskIdOrSlug
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Task cancelled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelTaskResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'
        '429':
          $ref: '#/components/responses/RateLimitedError'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    CancelTaskResponse:
      type: object
      required:
        - success
        - task
      properties:
        success:
          type: boolean
        task:
          type: object
          required:
            - id
          properties:
            id:
              type: string
    ApiErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            details: {}
  responses:
    UnauthorizedError:
      description: Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            error:
              code: unauthorized
              message: Invalid or missing API key
    NotFoundError:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            error:
              code: not_found
              message: Task not found
    RateLimitedError:
      description: Too many requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            error:
              code: rate_limited
              message: Rate limit exceeded. Max 100 requests per minute.
    InternalError:
      description: Server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            error:
              code: internal_error
              message: Server error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````