Gateway API 文档

OpenAI 兼容
GET/openai/v1/batches/{batch_id}

Batch 查询

查询批量任务的状态与进度。仅能查询属于当前账户的 batch(越权返回 404)。返回 OpenAI 原生 batch 对象,完成后含 output_file_id / error_file_id,可用 `GET /openai/v1/files/{id}/content` 下载结果。

需要认证

调用示例

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())
}

响应示例

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

注意:配套端点(归属隔离): - `GET /openai/v1/batches` 列出本账户的 batch(本地回放)。 - `POST /openai/v1/batches/{id}/cancel` 取消进行中的 batch。 客户只持有 GatewayKey、无法直连上游,因此必须经网关查询/下载结果;网关据此保证归属隔离与计费。