任务接口
用已上传的输入文件创建任务、查询进度与取消任务。创建任务后立即返回
validating任务对象,执行在后台异步进行,调用方通过轮询任务详情获取进度。任务对象字段、任务状态与结果文件格式见 接口概览 · 输出数据对象。
权限范围
任务完全按 API Key 隔离,只能由创建它的 API Key 查询和取消,GET /v1/batches 只返回当前 API Key 的任务,其他 API Key 访问返回 404 batch_not_found(同一账号或同一企业下的其他 API Key 也不例外)。详见 接口概览 · 数据可见范围。
创建任务
接口地址
http
POST /v1/batches请求头
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
Authorization | string | 是 | Bearer <api-key> |
Content-Type | string | 是 | application/json |
请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
input_file_id | string | 是 | 已上传的 purpose=batch 文件标识 |
endpoint | string | 是 | 任务端点,当前仅支持 /v1/chat/completions |
completion_window | string | 否 | 完成窗口,只接受 24h(不传按 24h 处理) |
metadata | object<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等尚未产生的字段。
错误响应
| HTTP | code | 说明 |
|---|---|---|
| 400 | invalid_request | 请求体不是合法 JSON |
| 400 | missing_input_file_id | 缺少 input_file_id |
| 400 | missing_endpoint | 缺少 endpoint |
| 400 | invalid_batch | 文件结构校验失败(多模型、多 endpoint、custom_id 重复、completion_window 非法、metadata 超限等) |
| 403 | model_access_denied | 无权访问文件中的模型 |
| 403 | no_batch_channel | 当前配置暂不支持批处理 |
| 403 | no_batch_group | 当前 API Key 未开通批处理 |
| 402 | insufficient_quota | 余额不足以支付本任务 |
| 404 | file_not_found | input_file_id 不存在或不属于当前 API Key |
| 429 | batch_limit_exceeded | 超过批处理提交上限 |
| 503 | object_storage_unconfigured | 批处理服务暂不可用 |
| 503 | batch_create_budget_exceeded | 创建任务超时,请稍后重试或减小文件 |
查询任务列表
接口地址
http
GET /v1/batches请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
limit | int | 否 | 每页条数,默认 20,最大 100 |
after | string | 否 | 游标:上一页返回的 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。
错误响应
| HTTP | code | 说明 |
|---|---|---|
| 400 | invalid_limit | limit 不是正整数 |
| 400 | invalid_after | after 游标非法或指向不存在的任务 |
查询任务详情
接口地址
http
GET /v1/batches/{id}请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 任务标识 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:出现后即可下载结果。
错误响应
| HTTP | code | 说明 |
|---|---|---|
| 404 | batch_not_found | 任务不存在或不属于当前 API Key |
取消任务
接口地址
http
POST /v1/batches/{id}/cancel请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 任务标识 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 | 幂等,返回当前任务对象 |
取消后不再派发新请求;已在执行的请求允许完成并按实际用量计费,未执行的请求不产生费用。
错误响应
| HTTP | code | 说明 |
|---|---|---|
| 400 | batch_not_cancellable | 任务已结束或正在生成结果,不可取消 |
| 404 | batch_not_found | 任务不存在或不属于当前 API Key |
