Skip to main content
Batches

查询 Batch 子任务

GET /api/v1/forward/batches/{batch_id}/tasks 分页查询 Batch 内逐条任务的状态、结果摘要、错误、制品和用量。Batch 处于任意状态时均可调用。只返回当前 PAT 用户所属 Batch 的子任务。

请求头

Header是否必填说明
AuthorizationBearer <PAT>

路径参数

参数类型是否必填说明
batch_idstringBatch ID。

查询参数

参数类型是否必填默认值说明
statusstring-按任务状态过滤:pendingrunningcompletedfailedcancelledexpired
custom_idstring-按调用方任务标识精确过滤,仅支持单值;未命中返回空列表。
limitinteger20分页大小,最大 100。
after_idstring-向后翻页游标,传上一页响应的 last_id;游标必须属于当前 Batch。

示例请求

curl -s -X GET 'https://api.qoder.com.cn/api/v1/forward/batches/batch_completed001/tasks?limit=20' \
  -H "Authorization: Bearer $QODER_ACCESS_TOKEN"

示例响应

HTTP 200 OK
{
  "object": "list",
  "data": [
    {
      "custom_id": "task-001",
      "status": "completed",
      "started_at": "2026-08-06T14:01:03Z",
      "completed_at": "2026-08-06T14:03:41Z",
      "output_summary": "report generated",
      "usage": {
        "total_credits": 2.75
      },
      "artifacts": [
        {
          "file_id": "file_abc",
          "name": "report.xlsx",
          "size": 20480,
          "content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        }
      ]
    },
    {
      "custom_id": "task-002",
      "status": "failed",
      "started_at": "2026-08-06T14:01:03Z",
      "completed_at": "2026-08-06T14:01:20Z",
      "error": {
        "code": "session_error",
        "message": "sandbox terminated unexpectedly"
      },
      "usage": {
        "total_credits": 0.5
      },
      "artifacts": []
    }
  ],
  "has_more": true,
  "first_id": "task-001",
  "last_id": "task-002"
}

响应字段

字段类型说明
objectstring固定为 list
dataarray当前页的 Batch Task 对象。
data[].custom_idstring调用方任务标识,也是当前版本的公开分页游标。
data[].statusstring任务状态,与 Batch request_counts 明细状态口径一致。
data[].started_atstring最终一次持久化执行尝试的开始时间,RFC 3339 UTC;未开始时省略。
data[].completed_atstring任务完成时间,RFC 3339 UTC;未完成时省略。
data[].output_summarystring最终回复文本,最多 500 个 Unicode 字符;无结果时省略。
data[].errorobjectfailed 任务返回,包含 codemessage
data[].artifactsarray已交付制品;无制品时返回空数组。
data[].usageobject最终或当前 CAS Session 的用量;CAS 未返回合法用量时省略。
data[].usage.total_creditsnumberCAS Session 累计 Credit 消耗;不代表 token 数或货币金额,显式零值保留。
first_idstring当前页第一条任务的 custom_id
last_idstring当前页最后一条任务的 custom_id
has_moreboolean是否还有更多任务。
瞬时错误重试会为任务创建新 CAS Session,因此 usage 只表示最终或当前 Session,不累加已被替换的历史 Session。

错误码

HTTPTypeCode触发条件
400invalid_request_errorinvalid_requeststatuslimitafter_id 不合法。
404not_found_errorbatch_not_foundBatch 不存在、跨用户访问,或结果文件已完成 30 天清理。
401authentication_errorauthentication_requiredPAT 无效或已过期。

注意事项

  • has_more=true 时,将 last_id 原样作为下一次请求的 after_id
  • 制品下载复用 Files API,不新增 Batch 专用制品下载端点。

相关