Skip to main content
Batch

Cancel batch

Cancel an in-progress or queued batch job. The status changes to cancelling while currently executing requests complete, then to cancelled. Completed requests before cancellation are still billed.

POST
/batches/{batch_id}/cancel
Python
from openai import OpenAI
import os

client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)

batch = client.batches.cancel("batch_abc123")

print(f"Status: {batch.status}")
{
  "id": "batch_abc123",
  "object": "batch",
  "endpoint": "/v1/chat/completions",
  "errors": {
    "object": "list",
    "data": [
      {
        "code": "<string>",
        "message": "<string>",
        "param": "<string>",
        "line": 0
      }
    ]
  },
  "input_file_id": "file-abc123",
  "completion_window": "24h",
  "status": "validating",
  "output_file_id": "file-xyz789",
  "error_file_id": "file-err456",
  "created_at": 1735113344,
  "in_progress_at": 0,
  "expires_at": 0,
  "finalizing_at": 0,
  "completed_at": 0,
  "failed_at": 0,
  "expired_at": 0,
  "cancelled_at": 0,
  "cancelling_at": 0,
  "request_counts": {
    "total": 0,
    "completed": 0,
    "failed": 0
  },
  "metadata": {
    "ds_name": "<string>",
    "ds_description": "<string>"
  }
}

Authorizations

string
header
required

Qwen Cloud API Key. Create one in the console.

Path Parameters

string
required

The ID of the batch job to cancel.

batch_abc123

Response

200-application/json
string

Unique batch job identifier.

batch_abc123
enum<string>

Always "batch".

batch
string

The API endpoint used for this batch.

/v1/chat/completions
object | null

Errors encountered during batch processing.

string

ID of the input file.

file-abc123
string

The completion window for the batch job.

24h
enum<string>

Current status of the batch job. validating: input file is being validated. in_progress: batch is being processed. finalizing: results are being compiled. completed: all requests finished. failed: job failed. expired: job exceeded the completion window. cancelling: cancellation in progress. cancelled: job was cancelled.

validating,in_progress,finalizing,completed,failed,expired,cancelling,cancelled
string | null

ID of the file containing successful results. Available when status is completed. Use with the download file content endpoint.

file-xyz789
string | null

ID of the file containing error details. Available when some requests failed. Use with the download file content endpoint.

file-err456
integer

Unix timestamp (seconds) when the batch was created.

1735113344
integer | null

Unix timestamp (seconds) when the batch started processing.

integer | null

Unix timestamp (seconds) when the batch will expire.

integer | null

Unix timestamp (seconds) when the batch started finalizing.

integer | null

Unix timestamp (seconds) when the batch completed.

integer | null

Unix timestamp (seconds) when the batch failed.

integer | null

Unix timestamp (seconds) when the batch expired.

integer | null

Unix timestamp (seconds) when the batch was cancelled.

integer | null

Unix timestamp (seconds) when the batch entered cancelling status.

object

Request processing counts.

object | null

Key-value metadata attached to the batch.