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

# Cancel batch documents

> Cancel pending or processing documents in a batch.

Flips PENDING/PROCESSING rows to CANCELLED. Completed rows are never touched. Credits already spent are **not** refunded. With `document_ids` omitted, the batch itself becomes CANCELLED.

Idempotent: a second call returns 200 with `cancelled_doc_count == 0`.


## OpenAPI

````yaml POST /api/v2/batches/{batch_id}/cancel/
openapi: 3.1.0
info:
  title: Abacus Docs API
  version: 1.0.0
  description: |
    REST + SSE surface for Abacus Docs on the same host as the web app
    (`https://abacusdocs.com`). Paths are `/api/v2/…`.

    Authenticate with an organisation API key (`sk-abacus-*`) as a Bearer
    token, or an Auth0 access token. Cross-tenant reads return **404**, not
    403. Page-based lists use `?page=` and `?page_size=`.

    Extraction, reprocess, schema tests, and chat turns spend credits.
    See the help centre Credits pages for rates.
  contact:
    name: Abacus Docs
    url: https://abacusdocs.com/contact
servers:
  - url: https://abacusdocs.com
    description: Production (Extract)
security: []
paths:
  /api/v2/batches/{batch_id}/cancel/:
    post:
      tags:
        - v2/batches
      summary: Cancel pending/processing docs in a batch
      description: >-
        Flips one, several, or all PENDING / PROCESSING ``BatchDocument`` rows
        to ``CANCELLED``. Already-COMPLETED docs are NEVER touched (work and
        credits already spent). Idempotent — re-posting when nothing is
        cancellable returns 200 with ``cancelled_doc_count == 0``.


        **Per-row cancel** (`document_ids` provided): only the listed docs are
        flipped. The parent ``Batch.status`` is left untouched.


        **Full-batch cancel** (`document_ids` omitted/empty): every non-terminal
        doc is flipped AND ``Batch.status`` becomes ``CANCELLED`` (terminal).
        Reprocess + add-documents are blocked on terminal batches.


        Note: docs already in ``PROCESSING`` finish their in-flight Lynx call;
        the worker's terminal status update uses ``filter(status=PROCESSING)``
        so the cancelled row silently skips the COMPLETED transition. Credits
        already deducted are NOT refunded.
      operationId: v2_batches_cancel_create
      parameters:
        - in: path
          name: batch_id
          schema:
            type: integer
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BatchCancelRequestRequest'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchCancelResponse'
          description: ''
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '403':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '404':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
      security:
        - extractApiKey: []
        - bearerAuth: []
        - cookieAuth: []
components:
  schemas:
    BatchCancelRequestRequest:
      type: object
      description: >-
        Body for POST /api/v2/batches/{batch_id}/cancel/ (AD-178).


        Cancels one, several, or all PENDING / PROCESSING ``BatchDocument`` rows

        in a batch. Already-COMPLETED docs are NEVER touched (work and credits

        already spent). The cancel endpoint is intentionally idempotent:
        re-posting

        when nothing is cancellable returns 200 with ``cancelled_doc_count ==
        0``.


        Cancel semantics:


        * **Per-row cancel** (``document_ids`` provided): only the listed docs
          are flipped to ``CANCELLED``. The parent ``Batch.status`` is left
          untouched — the batch can still complete on its remaining docs.
        * **Full-batch cancel** (``document_ids`` omitted or empty): every
          non-terminal doc is flipped to ``CANCELLED`` AND ``Batch.status`` is
          set to ``CANCELLED`` (terminal). Subsequent reprocess + re-add are
          blocked by the terminal-batch guard in those endpoints.

        For docs already in ``PROCESSING`` at cancel time, the worker's
        in-flight

        Lynx gRPC call is NOT aborted mid-stream — the call finishes and the

        extraction result is saved on the attachment. But the worker's terminal

        status update uses ``filter(status=PROCESSING)`` so a doc that flipped

        to CANCELLED in the meantime will silently skip the COMPLETED transition

        and stay CANCELLED. Credits already deducted are NOT refunded.


        Fields:
            document_ids: Optional list of ``BatchDocument`` PKs to cancel.
                When omitted (or empty), every non-terminal doc in the batch is
                cancelled and the batch itself transitions to ``CANCELLED``.
      properties:
        document_ids:
          type: array
          items:
            type: integer
            minimum: 1
          description: >-
            Optional list of BatchDocument PKs to cancel. Omit (or send an empty
            list) to cancel every non-terminal doc in the batch AND set
            Batch.status to CANCELLED.
          maxItems: 1024
    BatchCancelResponse:
      type: object
      description: |-
        Response shape for POST /api/v2/batches/{batch_id}/cancel/.

        Fields:
            batch: Updated parent batch (status flipped to CANCELLED on
                full-batch cancel; unchanged on per-row cancel).
            cancelled_doc_count: Number of ``BatchDocument`` rows whose status
                actually flipped to ``CANCELLED`` on this call. Zero when the
                request matched no cancellable docs (still 200 — idempotent).
            full_batch: True when this call cancelled the whole batch
                (``document_ids`` was omitted/empty), False for per-row cancel.
      properties:
        batch:
          $ref: '#/components/schemas/BatchSummary'
        cancelled_doc_count:
          type: integer
        full_batch:
          type: boolean
      required:
        - batch
        - cancelled_doc_count
        - full_batch
    BatchSummary:
      type: object
      description: >-
        Compact projection of a Batch row for responses that need to echo

        the parent batch state alongside per-row payloads.


        Currently used by ``BatchReprocessResponse`` so the SPA can update its

        batch header (status pill, default version chip) without a follow-up
        GET.
      properties:
        id:
          type: integer
        name:
          type: string
        status:
          type: string
        total_files:
          type: integer
        succeeded_count:
          type: integer
        failed_count:
          type: integer
        default_version_number:
          type:
            - integer
            - 'null'
          description: >-
            Version number of Batch.default_struct_version, or null for plain
            batches.
      required:
        - default_version_number
        - failed_count
        - id
        - name
        - status
        - succeeded_count
        - total_files
  securitySchemes:
    extractApiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        Organisation API key from Settings → API / `/api/keys/`. The secret is
        shown once. Send `Authorization: Bearer sk-abacus-…`. One active key
        per organisation. Ingest (`/api/v2/ingest/*`) refuses API keys — that
        surface is Auth0-only with `ingest:read` / `ingest:write` scopes.
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        Auth0 access token for a signed-in user. Send `Authorization: Bearer
        <token>`.

        The SPA and desktop agent use this. Prefer an organisation API key for

        server-to-server integrations.
    cookieAuth:
      type: apiKey
      in: cookie
      name: sessionid
      description: |
        Django session cookie from a browser login. Present so the web app can
        call `/api/v2` without a header. Do not rely on this for integrations.

````