Skip to content

调用流程 ​

一次完整的批处理调用分为四步:上传输入文件 → 创建任务 → 轮询状态 → 下载结果。下面给出流程说明与可直接运行的示例。

流程概览 ​

1. POST /v1/files                         上传 JSONL(purpose=batch)        → file-xxx
2. POST /v1/batches                       用 input_file_id 创建任务          → batch-xxx(validating)
3. GET  /v1/batches/{id}                  轮询状态,直到任务结束
4. GET  /v1/files/{output_file_id}/content 下载成功结果 JSONL
   GET  /v1/files/{error_file_id}/content  下载失败结果 JSONL(如有)

结束状态为 completed、cancelled、expired、failed。

使用同一 API Key

文件、任务与结果文件都完全归属于上传 / 创建任务的 API Key,四个步骤必须使用同一个 API Key;中途更换 API Key(即使同属一个账号或企业)会在读取或下载时返回 404。详见 接口概览 · 数据可见范围。

步骤 1:上传输入文件 ​

准备 JSONL 文件,完整格式见 接口概览 · 输入 JSONL 格式。示例:

jsonl
{"custom_id":"req-1","method":"POST","url":"/v1/chat/completions","body":{"model":"glm-5.3","messages":[{"role":"user","content":"one"}]}}
bash
curl --request POST \
  --url 'https://neolink.com/api/v1/files' \
  --header 'Authorization: Bearer <api-key>' \
  --header 'Content-Type: multipart/form-data' \
  --form 'purpose=batch' \
  --form 'file=@batch1.jsonl'

从响应中取 id 作为下一步的 input_file_id。

步骤 2:创建任务 ​

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"
  }'

创建成功后返回的 status 为 validating。

步骤 3:轮询任务状态 ​

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

轮询建议:任务创建后先每 10–30 秒查询一次;字段含义见 任务接口 · 查询任务详情。

步骤 4:下载结果文件 ​

bash
# 成功结果
curl --location 'https://neolink.com/api/v1/files/file-fa7326de39c3402cbc12007522f78c69/content' \
  --header 'Authorization: Bearer <api-key>' \
  -o output.jsonl

# 失败结果(任务有失败行时才有 error_file_id)
curl --location 'https://neolink.com/api/v1/files/file-1234deadbeef/content' \
  --header 'Authorization: Bearer <api-key>' \
  -o error.jsonl

结果行为 JSONL,按 custom_id 与输入行匹配,示例见 接口概览 · 结果文件行。

中途放弃可调用 取消任务;调用失败时按 错误码 排查。