跳转到主要内容
批量

列出 Batch

GET
/batches
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",
)

batches = client.batches.list(limit=2)

for batch in batches.data:
  print(batch.id, batch.status)
{
  "object": "list",
  "data": [
    {
      "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>"
      }
    }
  ],
  "first_id": "batch_abc123",
  "last_id": "batch_abc456",
  "has_more": false
}

鉴权

string
header
必填

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

查询参数

string

分页游标。值为上一页最后一个批量任务的 ID。

batch_abc123
integer
默认值20

每页返回的任务数量。取值范围:[1, 100],默认值:20。

20
1 <= x <= 100
string

按任务名称模糊匹配。

string

按输入文件 ID 筛选。多个 ID 用逗号分隔,最多 20 个。

file-abc123,file-def456
string

按任务状态筛选。多个状态用逗号分隔。可选值:validatingin_progressfinalizingcompletedfailedexpiredcancellingcancelled

completed,expired
string

筛选在该时间点之后创建的任务。格式:yyyyMMddHHmmss

20250304000000
string

筛选在该时间点之前创建的任务。格式:yyyyMMddHHmmss

20250306123000

响应

200-application/json
enum<string>

固定为 list

list
object[]

批量任务对象列表。

string | null

列表中第一个批量任务的 ID。

batch_abc123
string | null

列表中最后一个批量任务的 ID。

batch_abc456
boolean

当前页之后是否还有更多批量任务。