OpenAI 列出批处理

2026-11-12 13:52 更新

列出批处理

get /batches

列出组织的批处理。

查询参数

  • after: optional string

分页游标。after 使用对象 ID 表示列表中的位置。例如,本次返回 100 个对象,最后一个为 obj_foo,则下次可传入 after=obj_foo 获取下一页。

  • limit: optional integer (default: 20)

返回对象数量上限,范围为 1–100,默认为 20。

返回值

  • data: array of Batch

  • id: string

  • completion_window: string

批处理应完成处理的时间范围。

  • created_at: integer

创建批处理时的 Unix 时间戳,单位为秒。

format: unixtime

  • endpoint: string

批处理使用的 OpenAI API 端点。

  • input_file_id: string

批处理输入文件的 ID。

  • object: "batch"

对象类型,始终为 batch。

  • "batch"

  • status: "validating" or "failed" or "in_progress" or 5 more

批处理的当前状态。

  • "validating"

  • "failed"

  • "in_progress"

  • "finalizing"

  • "completed"

  • "expired"

  • "cancelling"

  • "cancelled"

  • cancelled_at: optional integer or null

批处理被取消时的 Unix 时间戳,单位为秒。

format: unixtime

  • cancelling_at: optional integer or null

批处理开始取消时的 Unix 时间戳,单位为秒。

format: unixtime

  • completed_at: optional integer or null

批处理完成时的 Unix 时间戳,单位为秒。

format: unixtime

  • error_file_id: optional string or null

包含错误请求输出的文件的 ID。

  • errors: optional object { data, object } or null

  • data: optional array of BatchError

  • code: optional string

标识错误类型的错误代码。

  • line: optional integer or null

输入文件中发生错误的行号(如适用)。

  • message: optional string

便于人阅读、包含更多错误详情的消息。

  • param: optional string or null

导致错误的参数名称(如适用)。

  • object: optional string

对象类型,始终为 list。

  • expired_at: optional integer or null

批处理过期时的 Unix 时间戳,单位为秒。

format: unixtime

  • expires_at: optional integer or null

批处理将过期的 Unix 时间戳,单位为秒。

format: unixtime

  • failed_at: optional integer or null

批处理失败时的 Unix 时间戳,单位为秒。

format: unixtime

  • finalizing_at: optional integer or null

批处理开始收尾时的 Unix 时间戳,单位为秒。

format: unixtime

  • in_progress_at: optional integer or null

批处理开始处理时的 Unix 时间戳,单位为秒。

format: unixtime

  • metadata: optional Metadata or null

可附加到对象的元数据,最多包含 16 组键值对,可 以结构化方式存储对象的额外信息, 并通过 API 或控制台查询对象。

键为最多 64 个字符的字符串,值为 最多 512 个字符的字符串。

  • model: optional string

用于处理批处理的模型 ID,例如 gpt-6-astra。OpenAI 提供多种能力、性能特点和价格各异的模型。请参阅模型指南,浏览和比较可用模型。

  • output_file_id: optional string or null

包含成功执行请求输出的文件的 ID。

  • request_counts: optional BatchRequestCounts

批处理中不同状态的请求计数。

  • completed: integer

成功完成的请求数量。

  • failed: integer

失败的请求数量。

  • total: integer

批处理中的请求总数。

  • usage: optional BatchUsage

词元用量详情,包括输入词元、输出词元、 输出词元明细和词元总数。仅在 2025 年 9 月 7 日之后创建的批处理中填充。

  • input_tokens: integer

输入词元数量。

  • input_tokens_details: object { cached_tokens }

输入词元的详细分类统计。

  • cached_tokens: integer

从缓存中读取的词元数量。了解提示词缓存。

  • output_tokens: integer

输出词元数量。

  • output_tokens_details: object { reasoning_tokens }

输出词元的详细分类统计。

  • reasoning_tokens: integer

推理词元数量。

  • total_tokens: integer

使用的总词元数。

  • has_more: boolean

  • object: "list"

  • "list"

  • first_id: optional string

  • last_id: optional string

示例

## 先设置 OPENAI_API_KEY;按当前接口需要替换示例 ID 和参数。
curl https://api.openai.com/v1/batches \
    -H "Authorization: Bearer $OPENAI_API_KEY"

200 响应示例

{
  "data": [
    {
      "id": "id",
      "completion_window": "completion_window",
      "created_at": 0,
      "endpoint": "endpoint",
      "input_file_id": "input_file_id",
      "object": "batch",
      "status": "validating",
      "cancelled_at": 0,
      "cancelling_at": 0,
      "completed_at": 0,
      "error_file_id": "error_file_id",
      "errors": {
        "data": [
          {
            "code": "code",
            "line": 0,
            "message": "message",
            "param": "param"
          }
        ],
        "object": "object"
      },
      "expired_at": 0,
      "expires_at": 0,
      "failed_at": 0,
      "finalizing_at": 0,
      "in_progress_at": 0,
      "metadata": {
        "foo": "string"
      },
      "model": "model",
      "output_file_id": "output_file_id",
      "request_counts": {
        "completed": 0,
        "failed": 0,
        "total": 0
      },
      "usage": {
        "input_tokens": 0,
        "input_tokens_details": {
          "cached_tokens": 0
        },
        "output_tokens": 0,
        "output_tokens_details": {
          "reasoning_tokens": 0
        },
        "total_tokens": 0
      }
    }
  ],
  "has_more": true,
  "object": "list",
  "first_id": "batch_abc123",
  "last_id": "batch_abc456"
}

示例

## 先设置 OPENAI_API_KEY;按当前接口需要替换示例 ID 和参数。
curl https://api.openai.com/v1/batches?limit=2 \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json"

响应示例

{
  "object": "list",
  "data": [
    {
      "id": "batch_abc123",
      "object": "batch",
      "endpoint": "/v1/chat/completions",
      "errors": null,
      "input_file_id": "file-abc123",
      "completion_window": "24h",
      "status": "completed",
      "output_file_id": "file-cvaTdG",
      "error_file_id": "file-HOWS94",
      "created_at": 1711471533,
      "in_progress_at": 1711471538,
      "expires_at": 1711557933,
      "finalizing_at": 1711493133,
      "completed_at": 1711493163,
      "failed_at": null,
      "expired_at": null,
      "cancelling_at": null,
      "cancelled_at": null,
      "request_counts": {
        "total": 100,
        "completed": 95,
        "failed": 5
      },
      "metadata": {
        "customer_id": "user_123456789",
        "batch_description": "夜间任务"
      }
    }
  ],
  "first_id": "batch_abc123",
  "last_id": "batch_abc123",
  "has_more": false
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号