Skip to main content
POST
Cancel Batch
Cancel an in-progress batch task. After cancellation, the task status will change to cancelling and then to cancelled. Only tasks in validating, in_progress, or finalizing status can be cancelled.
On success, the endpoint returns a BatchObject containing the following fields:
FieldTypeDescription
idstringUnique identifier for the batch task
objectstringObject type, always batch
endpointstringRequest endpoint
input_file_idstringInput file ID
completion_windowstringProcessing time window
statusstringCurrent status. After a successful cancellation request this is typically cancelling, and eventually becomes cancelled
output_file_idstring | nullOutput file ID for successful results
error_file_idstring | nullError file ID for failed results
created_atintegerCreation timestamp (Unix)
in_progress_atinteger | nullExecution start timestamp (Unix)
expires_atinteger | nullExpiration timestamp (Unix)
finalizing_atinteger | nullResult preparation start timestamp (Unix)
completed_atinteger | nullCompletion timestamp (Unix)
failed_atinteger | nullValidation failure timestamp (Unix)
cancelling_atinteger | nullCancellation request timestamp (Unix)
cancelled_atinteger | nullCancellation completion timestamp (Unix)
request_countsobjectRequest counts, including completed, failed, and total
metadataobject | nullCustom metadata
Only tasks in validating, in_progress, or finalizing status can be cancelled. If the task is already completed, failed, expired, or cancelled, calling this endpoint will return a 400 error.
Common Errors
  • 400 Bad Request: The task status does not allow cancellation, or the request parameters are invalid. Please verify the task status before attempting cancellation.
  • 401 Unauthorized: Invalid or missing API key. Check that Authorization: Bearer <key> is correct.
  • 404 Not Found: The specified batch_id does not exist. Verify the ID is correct and the task belongs to your organization.
  • 500 Server Error: Internal server error. Please retry later; if the issue persists, contact support with the request_id.
For more details, see Error Codes.
For complete usage examples and status transitions, see the Batch API Guide.

Authorizations

Authorization
string
header
required

The Authorization header expects a Bearer token. Use an MOONSHOT_API_KEY as the token. This is a server-side secret key. Generate one on the API keys page in your dashboard.

Path Parameters

batch_id
string
required

The ID of the batch task

Response

The cancelled batch task

id
string
required

Unique identifier for the batch task

object
string
required

Object type, always batch

Example:

"batch"

endpoint
string
required

Request endpoint

input_file_id
string
required

Input file ID

completion_window
string
required

Processing time window

status
enum<string>
required

Current status: validating, failed, in_progress, finalizing, completed, expired, cancelling, cancelled

Available options:
validating,
failed,
in_progress,
finalizing,
completed,
expired,
cancelling,
cancelled
created_at
integer
required

Creation timestamp (Unix)

request_counts
object
required
output_file_id
string | null

Output file ID for successful results

error_file_id
string | null

Error file ID for failed results

in_progress_at
integer | null

Execution start timestamp (Unix)

expires_at
integer | null

Expiration timestamp (Unix)

finalizing_at
integer | null

Result preparation start timestamp (Unix)

completed_at
integer | null

Completion timestamp (Unix)

failed_at
integer | null

Validation failure timestamp (Unix)

cancelling_at
integer | null

Cancellation request timestamp (Unix)

cancelled_at
integer | null

Cancellation completion timestamp (Unix)

metadata
object | null

Custom metadata