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

# Cancel a task

> Stop a running task and refund what its unfinished requests reserved. Rows that already finished keep their results, so poll the task afterwards to collect them. A task that has already reached a terminal status returns 409.

<Info>
  Rows that already finished keep their results. Read them with [Get task status](/api-reference/endpoint/tasks-get-status) after cancelling — the `data` array holds only the finished rows, so unlike a completed bulk run it is **not** aligned to your inputs and cannot be joined back by position.
</Info>

<Info>
  Credits reserved by requests that had not finished are returned. You are only billed for the rows that produced data.
</Info>

<Warning>
  A task that has already reached a terminal status (`completed`, `partially_completed`, `failed`) returns **409**. Provider calls already in flight for a waterfall row may still finish, but you are not billed for them.
</Warning>


## OpenAPI

````yaml POST /v1/tasks/{task_id}/cancel
openapi: 3.1.0
info:
  title: Databar.ai API
  description: >-

    # Authentication


    Databar uses API keys to allow access to the API. You can find your API key
    in your workspace home page, but to use the REST API you’ll first need to
    schedule a call with us.

    Our API expects the API key to be included in all API requests to the server
    in the Header of your request with the key `x-apikey`.

    To find your API key, head over to your Databar workspace and click
    Integrations.


    **Example:**


    `bash

    curl https://api.databar.ai/v1/user/me -H x-apikey: {YOUR_API_KEY}`
  contact:
    email: info@databar.ai
  version: 0.1.2
servers:
  - url: https://api.databar.ai
    description: Production
security: []
paths:
  /v1/tasks/{task_id}/cancel:
    post:
      tags:
        - Get enrichment data or status
      summary: Cancel a running task
      description: >-
        Stop a running task and refund what its unfinished requests reserved.
        Rows that already finished keep their results, so poll the task
        afterwards to collect them. A task that has already reached a terminal
        status returns 409.
      operationId: cancel_task_v1_tasks__task_id__cancel_post
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
            description: The unique identifier of the task to cancel.
            title: Task Id
          description: The unique identifier of the task to cancel.
        - name: x-apikey
          in: header
          required: true
          schema:
            title: API Key
            description: API Key for authentication
          description: API Key for authentication
      responses:
        '200':
          description: The task was cancelled.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/app__api__v1__task__Task'
              example:
                task_id: abc123
                status: cancelled
                progress:
                  total: 100
                  completed: 42
                  failed: 3
                  processing: 55
                credits_spent: 4.2
        '403':
          description: Forbidden access
          content:
            application/json:
              example:
                detail: Forbidden
        '404':
          description: 'Not Found: Task with specified ID does not exist.'
        '409':
          description: The task has already finished.
          content:
            application/json:
              example:
                detail: Task has already finished
components:
  schemas:
    app__api__v1__task__Task:
      properties:
        task_id:
          type: string
          title: Task Id
          description: Unique identifier of the task.
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Request Id
          description: 'Deprecated: use task_id instead. Same value as task_id.'
          deprecated: true
        status:
          type: string
          title: Status
          description: >-
            Current status of the request. Can be 'processing', 'completed',
            'partially_completed', 'failed' or 'cancelled'.
        progress:
          anyOf:
            - additionalProperties:
                type: integer
              type: object
            - type: 'null'
          title: Progress
          description: >-
            How far a bulk run has got: `total`, `completed`, `failed` and
            `processing` counts of inputs. `failed` covers every finished input
            that produced no data, clean misses included. Omitted for single
            (non-bulk) runs.
        data:
          anyOf:
            - items: {}
              type: array
            - type: object
            - type: 'null'
          title: Data
          description: >-
            Resulting data once completed. For bulk runs this is an array
            aligned to the inputs: one element per input, in the same order they
            were submitted, with null for inputs that returned no data
            (len(data) equals the number of inputs, and data[i] is the result
            for input i). A single (non-bulk) run returns the result object
            directly.
        error:
          anyOf:
            - items:
                type: string
              type: array
            - type: string
            - type: 'null'
          title: Error
          description: Error message if the request has failed.
        credits_spent:
          type: number
          title: Credits Spent
          description: Total credits spent for this request.
          default: 0
      type: object
      required:
        - task_id
        - status
      title: Task

````