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

# Cancel Batch

> Stops work on the queued items of a batch. Items that are already running may still finish.

> [!NOTE]
>
> **Spotted the typo right after you hit send?** It happens to the best of us. Cancel the batch, and you only pay for items that complete successfully.
>
> * **Already finished:** Billed. These results are done and waiting for you.
> * **Still in the queue:** Never run, never billed. This is where the savings live.
> * **Running right now:** You only pay for successful items, as usual.
>
> Credits already spent are not refunded, but the rest of your batch stops costing you anything.

> [!TIP]
>
> **After you cancel:** The batch can still show `in_progress` until the running items finish or time out. Check progress with [Batch Info](https://docs.olostep.com/api-reference/batches/info.md). Cancel is safe to call again on the same batch.


## OpenAPI

````yaml openapi/batches.json POST /v1/batches/{batch_id}/cancel
openapi: 3.0.3
info:
  title: Batches API
  version: 1.0.0
servers:
  - url: https://api.olostep.com
security: []
paths:
  /v1/batches/{batch_id}/cancel:
    post:
      summary: Cancel a batch
      description: >-
        Cancels the **queued** items of a batch. Items already running may still
        finish. No request body is required. Calling cancel again on the same
        batch is safe: items that are already canceled are not counted again.
      parameters:
        - name: batch_id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the batch to cancel.
      responses:
        '200':
          description: Cancel summary for the whole batch.
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    description: Total items in the batch.
                  done_count:
                    type: integer
                    description: Items already finished or canceled before this call.
                  in_flight_count:
                    type: integer
                    description: Items already running. They are not canceled.
                  canceled_count:
                    type: integer
                    description: Queued items canceled by this call.
                required:
                  - total_count
                  - done_count
                  - in_flight_count
                  - canceled_count
              example:
                total_count: 100
                done_count: 12
                in_flight_count: 3
                canceled_count: 87
        '401':
          description: Authentication credentials are missing or invalid.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: invalid_api_key
                type: https://docs.olostep.com/errors/invalid_api_key
                status: 401
                title: Invalid or missing API key
                detail: The provided API key is invalid.
                created: 1704067200
                metadata: {}
        '404':
          description: Batch not found for the provided ID, or it belongs to another team.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: not_found
                type: https://docs.olostep.com/errors/not_found
                status: 404
                title: batch not found
                detail: No batch with id 'YOUR_BATCH_ID' exists for your team.
                created: 1704067200
                metadata: {}
        '409':
          description: The batch deadline has passed, so cancel is no longer allowed.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: resource_conflict
                type: https://docs.olostep.com/errors/resource_conflict
                status: 409
                title: Resource conflict
                detail: The batch deadline has passed.
                created: 1704067200
                metadata: {}
        '500':
          description: >-
            Internal server error. See [Internal
            Error](/api-reference/errors/internal_error) for details.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: internal_server_error
                type: https://docs.olostep.com/api-reference/errors/internal_error
                status: 500
                title: Internal Server Error
                detail: An unexpected error occurred
                created: 1704067200
                metadata: {}
      security:
        - Authorization: []
components:
  schemas:
    Error:
      type: object
      description: RFC 7807 Problem Details error response
      properties:
        id:
          type: string
          description: Unique error identifier
        object:
          type: string
          enum:
            - error
          description: Always 'error'
        code:
          type: string
          description: Machine-readable error code
        type:
          type: string
          format: uri
          description: URI reference identifying the problem type
        status:
          type: integer
          description: HTTP status code
        title:
          type: string
          description: Short, human-readable summary
        detail:
          type: string
          description: Human-readable explanation
        created:
          type: integer
          description: Unix timestamp
        metadata:
          $ref: '#/components/schemas/Metadata'
        errors:
          type: array
          description: Optional array of additional error details
          items: {}
      required:
        - id
        - object
        - code
        - type
        - status
        - title
        - detail
        - created
    Metadata:
      type: object
      description: >-
        Set of key-value pairs for storing additional information about an
        object. Follows Stripe's approach with validation rules: max 50 keys,
        key max 40 characters (no square brackets), value max 500 characters,
        all values stored as strings.
      additionalProperties:
        type: string
        maxLength: 500
        description: >-
          Metadata value (max 500 characters). Numbers and booleans are
          automatically converted to strings.
      maxProperties: 50
      example:
        order_id: '12345'
        customer_name: John Doe
        priority: high
        processed: 'true'
      x-validation-rules:
        max_keys: 50
        key_max_length: 40
        key_forbidden_chars:
          - '['
          - ']'
        value_max_length: 500
        value_types:
          - string
          - number (coerced)
          - boolean (coerced)
  securitySchemes:
    Authorization:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form Bearer <token>, where <token>
        is your auth token.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.