Files 上传(仅 Batch)

上传批量任务的 JSONL 输入文件,仅支持 purpose=batch。上传时逐行校验 custom_id、模型和 url,并冻结当时的价格规则;文件归属于当前账户。

POST /openai/v1/files需要 Gateway Key

快速上手

调用示例
typescript
import OpenAI from "openai"
import fs from "node:fs"

const client = new OpenAI({ baseURL: "https://llmapi.memene.cn/openai/v1", apiKey: "gw_memene_<keyId>_<secret>" })

// 仅支持 purpose="batch",上传 JSONL(每行一条 {custom_id, method, url, body})
const file = await client.files.create({
  file: fs.createReadStream("requests.jsonl"),
  purpose: "batch",
})
console.log(file.id)

注意事项

配套端点(只能访问本账户的资源,其他账户的返回 404):

  • GET /openai/v1/files 列出本账户上传的 Batch 文件。
  • GET /openai/v1/files/{id} 查询文件元信息。
  • GET /openai/v1/files/{id}/content 流式下载 Batch 结果。
  • DELETE /openai/v1/files/{id} 删除文件。

上传文件时检查余额;查询、下载和删除不检查余额,也不单独计费。

请求参数

Content-Type:multipart/form-data

参数必填说明
purpose
string
必填文件用途,**本网关仅允许 "batch"**。
file
file
必填JSONL 文件,每行一条 {custom_id, method, url, body} 请求;全文件同一模型、同一 url,不超过 50 MB。格式要求见「批量任务(Batch)」。

响应示例

json
{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1700000000,
  "filename": "requests.jsonl",
  "purpose": "batch"
}