
Cancel a Batch API job
Cancel a Batch API job
Stop pending work on a batch with POST https://api.x.ai/v1/batches/{batch_id}:cancel and your regular XAI_API_KEY. Overview of create / add / poll / results: Run a Batch API job.
Cancel
curl -X POST "https://api.x.ai/v1/batches/$BATCH_ID:cancel" \
-H "Authorization: Bearer $XAI_API_KEY"
import os
from xai_sdk import Client
client = Client(api_key=os.getenv("XAI_API_KEY"))
cancelled = client.batch.cancel(batch_id=batch.batch_id)
print(cancelled.batch_id, cancelled.state.num_success)
const response = await fetch(
`https://api.x.ai/v1/batches/${batchId}:cancel`,
{
method: "POST",
headers: { Authorization: `Bearer ${process.env.XAI_API_KEY}` },
},
);
const cancelled = await response.json();
console.log(cancelled.batch_id, cancelled.state?.num_success);
What stays available
- Requests that already finished keep their results. Fetch them the same way as a live batch: Get Batch API results.
- Pending requests are not processed. Their request state becomes
cancelled. - You cannot call AddBatchRequests on a cancelled batch.
- File-based batches (created with
input_file_id) follow the same cancel path.
Check GET /v1/batches/{batch_id} for state.num_cancelled alongside num_success / num_error / num_pending.
Pitfalls
- Cancel does not delete completed results. Download image/video URLs before they expire (1 hour).
- Batches also expire on their own (
expires_at). Cancel early if you want to stop spend on the remaining queue. - Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.