POST /v1/batches/:id/cancel
Cancel a batch that is currently being processed. Once cancelled, the batch cannot be resumed.Authentication
Requires provider authentication headers:Request
Headers
The provider to route the request to (e.g.,
openai)Bearer token for the provider API
Path Parameters
The ID of the batch to cancel
Response
The batch identifier
The object type, always “batch”
The status of the batch, which will be
cancelling or cancelledUnix timestamp of when the batch was cancelled
Example
Response Example
Cancellation Behavior
What Happens When You Cancel
- In Progress Requests: Requests currently being processed may complete
- Queued Requests: Requests that haven’t started processing are cancelled
- Output File: An output file is generated with all completed requests
- Billing: You’re only charged for completed requests
When Cancellation is Not Allowed
You cannot cancel a batch if its status is:completed- Batch has already finishedfailed- Batch has already failedcancelled- Batch is already cancelled
Use Cases
Long Running Batches
Long Running Batches
Cancel batches that are taking longer than expected, allowing you to debug and resubmit with optimizations.
Changed Requirements
Changed Requirements
If requirements change mid-processing, cancel the batch and submit a new one with updated parameters.
Error Detection
Error Detection
If you detect an error in your input file after submission, cancel the batch to avoid wasting resources.
Best Practices
After cancelling a batch, wait a few seconds before retrieving it again to ensure the cancellation has been processed.
Related Endpoints
Create Batch
Create a new batch
Retrieve Batch
Check batch status
List Batches
View all batches