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

# Cancel a Batch

> Stop a batch. Messages already checked keep their results; the rest are not billed.

Cancels a batch:

* A batch still `validating` ends at once, with nothing checked or billed.
* A batch `in_progress` moves to `canceling`. Messages not yet started are canceled and not billed. Messages already checked keep their results and are billed. The batch then finalizes and ends, with the results so far.

Canceling a batch that is already `canceling` or `finalizing` returns its current state. Needs a full-access API key.

## Path Parameters

**batch\_id** `string` *required*

The batch to cancel.

## Response

The batch, in the shape returned by [Get a Batch](https://docs.zerodrift.com/api-reference/batches/get-batch.md).

```bash cURL theme={null}
curl -X POST https://api.zerodrift.ai/api/v3/batches/BATCH_ID/cancel \
  -H "x-api-key: YOUR_API_KEY"
```

```json 409 Conflict theme={null}
{
  "api_version": "v3",
  "error": {
    "code": "batch_not_cancelable",
    "message": "batch 'batch_e511e74dd1ea49ba8c5f4293a68427be' is failed and cannot be canceled"
  }
}
```

## Errors

| Status | Code | Meaning |
| - | - | - |
| `404` | `batch_not_found` | No batch with this ID is yours. |
| `409` | `batch_not_cancelable` | The batch has already ended or failed. |


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