跳转到主要内容
批量

取消 Batch

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.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>"
  }
}

鉴权

string
header
必填

千问云 API Key。详见获取 API Key

路径参数

string
必填

要取消的批量任务 ID。

batch_abc123

响应

200-application/json
string

批量任务唯一标识符。

batch_abc123
enum<string>

固定为 "batch"

batch
string

该批量任务使用的 API 接口路径。

/v1/chat/completions
object | null

批量处理过程中遇到的错误。

string

输入文件的 ID。

file-abc123
string

批量任务的完成时间窗口。

24h
enum<string>

批量任务的当前状态。validating:正在验证输入文件。in_progress:正在处理中。finalizing:正在汇总结果。completed:所有请求已完成。failed:任务失败。expired:任务超过完成时间窗口。cancelling:正在取消中。cancelled:任务已取消。

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

包含成功结果的文件 ID。状态为 completed 时可用。通过下载文件内容接口获取。

file-xyz789
string | null

包含错误详情的文件 ID。部分请求失败时可用。通过下载文件内容接口获取。

file-err456
integer

批量任务创建时间的 Unix 时间戳(秒)。

1735113344
integer | null

批量任务开始处理时间的 Unix 时间戳(秒)。

integer | null

批量任务预计过期时间的 Unix 时间戳(秒)。根据创建时间和 completion_window 计算得出。

integer | null

批量任务开始汇总结果时间的 Unix 时间戳(秒)。

integer | null

批量任务完成时间的 Unix 时间戳(秒)。

integer | null

批量任务失败时间的 Unix 时间戳(秒)。

integer | null

批量任务实际过期时间的 Unix 时间戳(秒)。仅当任务状态为 expired 时有值。

integer | null

批量任务取消时间的 Unix 时间戳(秒)。

integer | null

批量任务进入取消中状态的 Unix 时间戳(秒)。

object

请求处理计数。

object | null

附加到批量任务的键值对元数据。