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

# Cancel Task

Cancel a task while it is still non-terminal. Tasks that have already `succeeded`, `failed`, `timeout`, or `canceled` cannot be canceled again.


## OpenAPI

````yaml mountsea-api.mint.json DELETE /ms/v1/tasks/{task_id}
openapi: 3.0.0
info:
  title: mountsea-api
  description: >-
    mountsea unified AI API — video, image, and audio generation.


    ### Async task flow

    1. `POST /ms/v1/run/{endpoint_slug}` — submit a job (returns Task with
    `status: queued`).

    2. `GET /ms/v1/tasks/{task_id}` — poll until `succeeded` (`output.images` /
    `output.videos` / `output.audio`) or `failed`/`timeout` (`error`).
       Or pass `webhook_url` in the submit body for a signed terminal callback (`x-ms-signature`).
    3. `GET /ms/v1/endpoints[/{slug}]` — marketplace listing with
    `input_schema`, `output_schema`, and `examples`.


    ### Request body

    - `{ "input": { ... } }` — all parameters and media URLs per endpoint
    `input_schema`.

    - Optional `webhook_url` for callbacks.


    ### SDK compatibility (optional)

    Prefer the native async API above? Skip this section.


    - **OpenAI SDK** — `baseURL = https://{gateway}/ms/v1`
      - Image (sync): `POST /ms/v1/images/generations|edits` — gpt-image-2 family
      - Video (async): `POST /ms/v1/videos` + `GET /ms/v1/videos/{id}` — sora-2 → Veo lite/pro slugs
    - **Gemini SDK** — `httpOptions.baseUrl = https://{gateway}/ms`
      - Image (sync): `POST /ms/v1beta/models/{model}:generateContent` — nano-banana family
      - Video (async): `POST /ms/v1beta/models/{model}:predictLongRunning` + poll `GET /ms/v1beta/operations/{task_id}`

    Unsupported `model` → **HTTP 400** before any task is created (no charge).

    Successful calls bill the **same endpoint slug** as the equivalent
    `/ms/v1/run/...` API.
  version: 1.0.0
  contact: {}
servers:
  - url: https://api.mountsea.ai
    description: API Gateway
security: []
tags:
  - name: Run
    description: Submit async tasks by endpoint slug
  - name: Tasks
    description: Poll or cancel tasks
  - name: Endpoints (marketplace)
    description: Endpoint catalog and schemas
  - name: SDK Compatibility
    description: >-
      OpenAI / Gemini official SDK — sync image APIs (same billing as native
      run)
  - name: Admin - Catalog (internal)
    description: Internal admin (swagger only, not public gateway)
paths:
  /ms/v1/tasks/{task_id}:
    delete:
      tags:
        - Tasks
      summary: Cancel task (only while not terminal)
      operationId: TaskController_cancel
      parameters:
        - name: task_id
          required: true
          in: path
          schema:
            type: string
            example: ms-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
      responses:
        '200':
          $ref: '#/components/responses/MsTaskResponse'
      security:
        - bearerAuth: []
components:
  responses:
    MsTaskResponse:
      description: Standard Task object
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/MsTask'
  schemas:
    MsTask:
      type: object
      description: >-
        mountsea standard Task object. Output shape depends on capability (image
        / video / audio).
      properties:
        task_id:
          type: string
          example: ms-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
        endpoint:
          type: string
          example: google/veo-3.1/text-to-video
        model:
          type: string
          example: veo-3.1
        capability:
          type: string
          enum:
            - image
            - video
            - audio
        mode:
          type: string
          example: text-to-video
        status:
          type: string
          enum:
            - queued
            - processing
            - succeeded
            - failed
            - timeout
            - canceled
        error:
          type: object
          nullable: true
          properties:
            code:
              type: integer
              example: 500
            message:
              type: string
              example: task failed
        created_at:
          type: string
          format: date-time
        started_at:
          type: string
          format: date-time
          nullable: true
        completed_at:
          type: string
          format: date-time
          nullable: true
        elapsed_ms:
          type: integer
          nullable: true
        output:
          nullable: true
          description: Populated when status=succeeded; null while in-flight.
          oneOf:
            - $ref: '#/components/schemas/MsTaskOutputVideo'
            - $ref: '#/components/schemas/MsTaskOutputImage'
            - $ref: '#/components/schemas/MsTaskOutputAudio'
      required:
        - task_id
        - endpoint
        - model
        - capability
        - mode
        - status
        - created_at
    MsTaskOutputVideo:
      type: object
      description: 'Succeeded task output: single video URL per task.'
      properties:
        videos:
          type: array
          description: Generated videos (typically one item)
          items:
            type: object
            properties:
              url:
                type: string
                format: uri
                description: Stable mountsea CDN URL
            required:
              - url
      required:
        - videos
    MsTaskOutputImage:
      type: object
      description: >-
        Succeeded task output: normalized images. Count matches actual produced
        items.
      properties:
        images:
          type: array
          description: Generated images (1..N)
          items:
            type: object
            properties:
              url:
                type: string
                format: uri
                description: Stable mountsea CDN URL (preferred)
              b64:
                type: string
                description: Base64 payload when URL unavailable
              mime:
                type: string
                description: MIME type, e.g. image/png
      required:
        - images
    MsTaskOutputAudio:
      type: object
      description: 'Succeeded task output: generated audio (CDN URL in audio.url).'
      properties:
        audio:
          type: object
          properties:
            url:
              type: string
              format: uri
              description: Stable mountsea CDN URL
            content_type:
              type: string
              description: MIME type, e.g. audio/mpeg
            file_name:
              type: string
              description: Suggested filename
          required:
            - url
      required:
        - audio
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````