Skip to content

任务接口 ​

用已上传的输入文件创建任务、查询进度与取消任务。创建任务后立即返回 validating 任务对象,执行在后台异步进行,调用方通过轮询任务详情获取进度。

任务对象字段、任务状态与结果文件格式见 接口概览 · 输出数据对象。

权限范围

任务完全按 API Key 隔离,只能由创建它的 API Key 查询和取消,GET /v1/batches 只返回当前 API Key 的任务,其他 API Key 访问返回 404 batch_not_found(同一账号或同一企业下的其他 API Key 也不例外)。详见 接口概览 · 数据可见范围。

创建任务 ​

接口地址 ​

http
POST /v1/batches

请求头 ​

参数名类型必填说明
Authorizationstring是Bearer <api-key>
Content-Typestring是application/json

请求参数 ​

字段类型必填说明
input_file_idstring是已上传的 purpose=batch 文件标识
endpointstring是任务端点,当前仅支持 /v1/chat/completions
completion_windowstring否完成窗口,只接受 24h(不传按 24h 处理)
metadataobject<string,string>否自定义键值对,最多 16 个键,键 ≤64 字符,值必须为字符串且 ≤512 字符

创建任务时的同步校验(任一不满足即拒绝创建,返回对应错误):

  • 文件存在且属于当前 API Key、purpose=batch;
  • 每行是合法 JSON 对象,包含 custom_id(非空、≤256 字符、批内唯一)、method(为空或 POST)、url、body;
  • 所有行 url 相同且等于创建任务 endpoint;
  • 所有行 body.model 存在且相同(一个任务只能有一个模型);
  • 行内 metadata 满足与创建任务 metadata 相同的限制;
  • 当前 API Key 有权使用文件中的模型(否则 403 model_access_denied);
  • 当前余额足以支付本任务(否则 402 insufficient_quota);
  • 未超过当前 API Key 的提交上限(否则 429 batch_limit_exceeded)。

请求示例 ​

bash
curl --request POST \
  --url 'https://neolink.com/api/v1/batches' \
  --header 'Authorization: Bearer <api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
    "input_file_id": "file-51428aca4e0a47808012aaa03d1734ff",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h",
    "metadata": {
      "job": "nightly"
    }
  }'

成功响应 ​

json
{
  "id": "batch-63c583173a0a472bb8d3e48207041690",
  "object": "batch",
  "endpoint": "/v1/chat/completions",
  "errors": null,
  "input_file_id": "file-51428aca4e0a47808012aaa03d1734ff",
  "completion_window": "24h",
  "status": "validating",
  "created_at": 1764031200,
  "in_progress_at": null,
  "expires_at": 1764117600,
  "finalizing_at": null,
  "completed_at": null,
  "cancelling_at": null,
  "cancelled_at": null,
  "expired_at": null,
  "failed_at": null,
  "request_counts": { "total": 4, "completed": 0, "failed": 0 },
  "metadata": { "job": "nightly" }
}

响应可能省略 output_file_id / error_file_id 等尚未产生的字段。

错误响应 ​

HTTPcode说明
400invalid_request请求体不是合法 JSON
400missing_input_file_id缺少 input_file_id
400missing_endpoint缺少 endpoint
400invalid_batch文件结构校验失败(多模型、多 endpoint、custom_id 重复、completion_window 非法、metadata 超限等)
403model_access_denied无权访问文件中的模型
403no_batch_channel当前配置暂不支持批处理
403no_batch_group当前 API Key 未开通批处理
402insufficient_quota余额不足以支付本任务
404file_not_foundinput_file_id 不存在或不属于当前 API Key
429batch_limit_exceeded超过批处理提交上限
503object_storage_unconfigured批处理服务暂不可用
503batch_create_budget_exceeded创建任务超时,请稍后重试或减小文件

查询任务列表 ​

接口地址 ​

http
GET /v1/batches

请求参数 ​

字段类型必填说明
limitint否每页条数,默认 20,最大 100
afterstring否游标:上一页返回的 last_id

请求示例 ​

bash
curl --location 'https://neolink.com/api/v1/batches?limit=20' \
  --header 'Authorization: Bearer <api-key>'

成功响应 ​

json
{
  "object": "list",
  "data": [
    {
      "id": "batch-63c583173a0a472bb8d3e48207041690",
      "object": "batch",
      "endpoint": "/v1/chat/completions",
      "errors": null,
      "input_file_id": "file-51428aca4e0a47808012aaa03d1734ff",
      "completion_window": "24h",
      "status": "in_progress",
      "created_at": 1764031200,
      "in_progress_at": 1764031215,
      "expires_at": 1764117600,
      "finalizing_at": null,
      "completed_at": null,
      "cancelling_at": null,
      "cancelled_at": null,
      "expired_at": null,
      "failed_at": null,
      "request_counts": { "total": 4, "completed": 2, "failed": 0 },
      "metadata": {}
    }
  ],
  "has_more": false,
  "first_id": "batch-63c583173a0a472bb8d3e48207041690",
  "last_id": "batch-63c583173a0a472bb8d3e48207041690"
}

按 created_at 倒序返回;first_id / last_id 在空列表时为 null。

错误响应 ​

HTTPcode说明
400invalid_limitlimit 不是正整数
400invalid_afterafter 游标非法或指向不存在的任务

查询任务详情 ​

接口地址 ​

http
GET /v1/batches/{id}

请求参数 ​

字段类型必填说明
idstring是任务标识 batch-...

请求示例 ​

bash
curl --location 'https://neolink.com/api/v1/batches/batch-63c583173a0a472bb8d3e48207041690' \
  --header 'Authorization: Bearer <api-key>'

成功响应 ​

返回任务对象,字段见 接口概览 · 任务对象。轮询时重点关注:

  • status:任务是否已结束(completed / cancelled / expired / failed);
  • request_counts:已成功/失败的请求数;
  • output_file_id / error_file_id:出现后即可下载结果。

错误响应 ​

HTTPcode说明
404batch_not_found任务不存在或不属于当前 API Key

取消任务 ​

接口地址 ​

http
POST /v1/batches/{id}/cancel

请求参数 ​

字段类型必填说明
idstring是任务标识 batch-...

请求示例 ​

bash
curl --request POST \
  --url 'https://neolink.com/api/v1/batches/batch-84ed677b391849d48368c9b85788638c/cancel' \
  --header 'Authorization: Bearer <api-key>'

成功响应 ​

返回取消后的任务对象。

当前状态行为
validating / in_progress返回 cancelling,最终变为 cancelled
cancelling / cancelled幂等,返回当前任务对象

取消后不再派发新请求;已在执行的请求允许完成并按实际用量计费,未执行的请求不产生费用。

错误响应 ​

HTTPcode说明
400batch_not_cancellable任务已结束或正在生成结果,不可取消
404batch_not_found任务不存在或不属于当前 API Key