codecamp

OpenAI 检索批处理

检索批处理

get /batches/{batch_id}

检索一个批处理。

路径参数

  • batch_id: string

要检索的批处理的 ID。

返回值

  • Batch object { id, completion_window, created_at, 19 more }

  • 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

使用的总词元数。

示例

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

200 响应示例

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

示例

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

响应示例

{
  "id": "batch_abc123",
  "object": "batch",
  "endpoint": "/v1/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": "夜间评测任务"
  }
}
OpenAI 创建批处理
OpenAI 列出批处理
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

其他能力与进阶指南

Embeddings 接口参考

审计日志接口参考

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }