Batch 查询
查询批量任务的状态与进度,只能查询本账户的任务(其他账户的返回 404)。完成后含 output_file_id / error_file_id,可用 `GET /openai/v1/files/{id}/content` 下载结果。
GET /openai/v1/batches/{batch_id}需要 Gateway Key快速上手
调用示例
typescript
import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://llmapi.memene.cn/openai/v1",
apiKey: "gw_memene_<keyId>_<secret>",
})
const batch = await client.batches.retrieve("batch_abc123")
console.log(batch.status, batch.output_file_id)
// completed 后下载结果(JSONL,每行一条结果):
if (batch.output_file_id) {
const content = await client.files.content(batch.output_file_id)
console.log(await content.text())
}注意事项
配套端点(只能访问本账户的资源):
GET /openai/v1/batches列出本账户的批量任务。POST /openai/v1/batches/{id}/cancel取消进行中的任务,已完成的请求仍会计费。
查询、下载和取消不检查余额,余额不足时也可以止损或取回结果。
响应示例
json
{
"id": "batch_abc123",
"object": "batch",
"endpoint": "/v1/chat/completions",
"status": "completed",
"input_file_id": "file-abc123",
"output_file_id": "file-out456",
"error_file_id": null,
"completion_window": "24h",
"request_counts": {
"total": 100,
"completed": 98,
"failed": 2
}
}