批处理任务
批处理(Batch)用于异步提交大批量模型请求:先把请求写入 JSONL 文件上传,再创建任务,平台在 24 小时窗口内完成执行,最后按
custom_id下载成功/失败结果文件。接口与 OpenAI Batch API 同形。文中的「任务」即 OpenAI Batch API 中的 batch 对象,接口路径、字段名与错误码仍为
batch(如/v1/batches、"object": "batch"、batch_not_found)。本文档覆盖文件接口与任务接口:先阅读「接口概览」了解通用约定与数据结构,再按需查看 文件接口、任务接口、调用流程 与 错误码。
数据权限
批处理的所有接口都完全按 API Key 隔离数据:文件、任务、结果文件仅对创建它们的 API Key 可见,列表接口也只返回当前 API Key 的数据;同一账号或同一企业下的不同 API Key 之间同样互不可见。详见数据可见范围。
能力与限制
- 支持端点:当前仅支持
/v1/chat/completions(OpenAI 兼容对话补全)。 - 单模型单端点:一个任务内所有请求必须使用同一模型、同一端点,
custom_id必须唯一。 - 完成窗口:固定
24h(completion_window=24h,创建后expires_at = created_at + 24h)。 - 状态语义:
completed只表示处理结束,不代表全部成功,成功/失败行数看request_counts。 - 结果匹配:结果行顺序不保证,调用方须按
custom_id匹配。
任务提交上限(每个 API Key):
| 限制 | 默认值 | 超限返回 |
|---|---|---|
| 进行中的任务数 | 20 | 429 batch_limit_exceeded |
| 待处理行数 | 200,000 | 429 batch_limit_exceeded |
| 待处理字节数 | 500 MB | 429 batch_limit_exceeded |
通用约定
基础地址与鉴权
- 基础地址:
https://neolink.com/api - 鉴权方式:所有接口在 Header 中携带 API Key
Authorization: Bearer <api-key>数据可见范围
批处理的所有接口都完全按 API Key 隔离数据:数据是否可见、能否操作,只由请求头中的 API Key 决定;同一账号或同一企业下的不同 API Key 之间也互不可见、互不可操作。
- 文件:
GET /v1/files、GET /v1/files/{id}、GET /v1/files/{id}/content、DELETE /v1/files/{id}只能操作当前 API Key 上传的文件;结果文件(batch_output/batch_error)归属于创建任务的 API Key。 - 任务:
GET /v1/batches、GET /v1/batches/{id}、POST /v1/batches/{id}/cancel只能操作当前 API Key 创建的任务。 - 列表隔离:文件列表与任务列表只返回当前 API Key 自身的数据,不会包含其他 API Key 上传的文件或创建的任务,同一账号或同一企业下的其他 API Key 也不例外。
- 引用校验:创建任务时
input_file_id必须属于当前 API Key,否则返回404 file_not_found;文件中的模型也必须在当前 API Key 的可调用范围内,否则返回403 model_access_denied。 - 不暴露存在性:访问不属于当前 API Key 的文件或任务统一返回
404 file_not_found/404 batch_not_found,而不是403,不会提示该资源是否真实存在。 - 限额独立:进行中任务数、待处理行数与待处理字节数等提交上限按 API Key 分别计算。
使用建议
一次批处理的完整流程(上传 → 创建任务 → 轮询 → 下载结果)必须始终使用同一个 API Key;更换 API Key 后将无法读取此前上传的文件、任务及其结果文件。
响应格式
批处理接口直接返回 OpenAI 同形对象,不使用 success/message/data 包络。
成功时,响应体顶层就是文件对象、任务对象或列表对象。
失败时(业务错误):
{
"error": {
"message": "错误说明",
"type": "invalid_request_error",
"param": "file",
"code": "invalid_jsonl"
}
}| 字段 | 类型 | 说明 |
|---|---|---|
message | string | 错误说明 |
type | string | invalid_request_error / permission_error / insufficient_quota / rate_limit_exceeded / server_error |
param | string | 出错的参数名,无对应参数时为 "" |
code | string | 可判别的错误码,见 错误码 |
输入 JSONL 格式
文件为每行一个 JSON 对象的 JSONL:
{"custom_id":"req-1","method":"POST","url":"/v1/chat/completions","body":{"model":"glm-5.3","messages":[{"role":"user","content":"one"}]}}
{"custom_id":"req-2","method":"POST","url":"/v1/chat/completions","body":{"model":"glm-5.3","messages":[{"role":"user","content":"你好"}]}}
{"custom_id":"req-3","method":"POST","url":"/v1/chat/completions","body":{"model":"glm-5.3","messages":[{"role":"user","content":"继续"}]}}| 字段 | 必填 | 说明 |
|---|---|---|
custom_id | 是 | 行标识,非空、≤256 字符、批内唯一;结果行按此字段匹配 |
method | 否 | 只允许 POST;省略时按 POST 处理 |
url | 是 | 必须为 /v1/chat/completions,且所有行一致、等于创建任务时的 endpoint |
body | 是 | 该行请求体(JSON 对象),必须包含 model,且所有行模型一致 |
说明:
- 任务请求始终以非流式方式执行,行内的
stream/stream_options不生效。 - 行内自定义字段会原样透传,上传的输入文件不会被修改。
- 空行会被忽略;文件首行允许 UTF-8 BOM。
输出数据对象
文件对象
{
"id": "file-fa7326de39c3402cbc12007522f78c69",
"object": "file",
"bytes": 1024,
"created_at": 1764031200,
"filename": "batch1.jsonl",
"purpose": "batch"
}| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 文件标识,形如 file-<32位hex> |
object | string | 固定 file |
bytes | int64 | 文件字节数 |
created_at | int64 | 创建时间,Unix 秒 |
filename | string | 文件名 |
purpose | string | batch(调用方上传)/ batch_output(成功结果)/ batch_error(失败结果) |
任务对象
{
"id": "batch-63c583173a0a472bb8d3e48207041690",
"object": "batch",
"endpoint": "/v1/chat/completions",
"errors": null,
"input_file_id": "file-51428aca4e0a47808012aaa03d1734ff",
"completion_window": "24h",
"status": "completed",
"output_file_id": "file-fa7326de39c3402cbc12007522f78c69",
"error_file_id": "file-1234deadbeef",
"created_at": 1764031200,
"in_progress_at": 1764031215,
"expires_at": 1764117600,
"finalizing_at": 1764031300,
"completed_at": 1764031310,
"cancelling_at": null,
"cancelled_at": null,
"expired_at": null,
"failed_at": null,
"request_counts": { "total": 4, "completed": 3, "failed": 1 },
"metadata": { "job": "nightly" },
"error_total": 1,
"warning_message": "2 行结果计价异常,已按 0 计费"
}| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 任务标识,形如 batch-<32位hex> |
object | string | 固定 batch |
endpoint | string | 任务端点,当前仅 /v1/chat/completions |
errors | array | null | 任务级错误明细 [{code, message, param?}],正常为 null |
error_total | int | 错误明细总数;平台扩展字段,为 0 时省略 |
input_file_id | string | 输入文件标识 |
completion_window | string | 固定回显 24h |
status | string | 任务状态,见「任务状态」 |
output_file_id | string | 成功结果文件标识;任务结束后且有成功行时才有值,否则字段省略 |
error_file_id | string | 失败结果文件标识;任务结束后且有失败行时才有值,否则字段省略 |
created_at | int64 | 创建时间,Unix 秒 |
in_progress_at | int64 | null | 开始执行时间,未开始为 null |
expires_at | int64 | null | 到期时间,等于 created_at + 24h |
finalizing_at | int64 | null | 开始生成结果文件的时间 |
completed_at | int64 | null | 处理结束时间(completed / failed / expired) |
cancelling_at | int64 | null | 取消请求受理时间 |
cancelled_at | int64 | null | 取消完成时间 |
expired_at | int64 | null | 过期时间 |
failed_at | int64 | null | 失败时间 |
request_counts | object | {total, completed, failed}:总行数、成功行数、失败行数 |
metadata | object | 创建任务时提交的字符串键值对,原样回显;未提交时为 {} |
warning_message | string | 平台扩展字段:非失败类告警信息,无告警时省略 |
任务状态
| 状态 | 含义 | 是否结束 |
|---|---|---|
validating | 已受理,正在准备执行 | 否 |
in_progress | 执行中 | 否 |
finalizing | 正在生成结果文件 | 否 |
cancelling | 正在取消 | 否 |
completed | 处理结束(不代表全部成功) | 是 |
cancelled | 已取消 | 是 |
expired | 超过 24 小时窗口 | 是 |
failed | 任务失败(如服务异常导致任务无法执行) | 是 |
典型迁移:validating → in_progress → finalizing → completed;取消为 validating/in_progress → cancelling → cancelled;到期为 → expired。
结果文件行
output_file_id 与 error_file_id 指向平台托管的结果文件,内容为 OpenAI Batch 同形的 JSONL,每行至少包含 custom_id 与 id。
成功行:
{"id":"req-1","custom_id":"req-1","response":{"status_code":200,"body":{"id":"...","object":"chat.completion","choices":[],"usage":{"prompt_tokens":10,"completion_tokens":20,"total_tokens":30}}},"error":null}失败行:
{"id":"req-2","custom_id":"fail-1","response":{"status_code":400,"body":{"error":{"code":"invalid_request","message":"..."}}},"error":{"code":"invalid_request","message":"..."}}request_counts.completed等于输出文件行数,request_counts.failed等于错误文件行数。- 结果文件在所属任务处理完成前不允许删除。
