> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建批处理

> 从上传的输入文件创建一个与OpenAI兼容的批处理作业。

## 概述

此端点是TokenLab的与OpenAI兼容的批处理API的一部分。批处理作业使用上传的JSONL文件，异步运行，并可以在稍后返回输出/错误文件。

## 注意事项

* 批处理输入文件必须使用 `purpose=batch`。
* `completion_window` 当前为 `24h`。
* 输出顺序不保证；始终通过 `custom_id` 匹配。
* 批处理项内不支持流式传输。
* 当前支持的批处理项端点是 `/v1/chat/completions` 和 `/v1/embeddings`；在原生 Responses 批处理执行器可用之前，`/v1/responses` 批处理作业会被拒绝。

## 示例

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/batches" \
    -H "Authorization: Bearer sk-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "input_file_id": "file_abc123",
      "endpoint": "/v1/chat/completions",
      "completion_window": "24h"
    }'
  ```
</RequestExample>

## 请求 / 响应

使用上面的交互式OpenAPI面板获取确切的架构。

## 操作提示

* 使用 `custom_id` 进行幂等的下游对账。
* 仅在工作者完成批处理后，期待 `output_file_id` 和 `error_file_id`。
* 批处理定价可能与同步定价不同，因为适用 `isBatchRequest=true` 的折扣规则。

## 响应示例

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "id": "batch_abc123",
    "object": "batch",
    "endpoint": "/v1/chat/completions",
    "input_file_id": "file_abc123",
    "completion_window": "24h",
    "status": "validating",
    "output_file_id": null,
    "error_file_id": null,
    "created_at": 1706000000
  }
  ```
</ResponseExample>

## 重要字段

<ResponseField name="id" type="string">用于后续调用和支持排障的标识符。</ResponseField>
<ResponseField name="status" type="string">该资源当前的生命周期状态。</ResponseField>
<ResponseField name="output_file_id" type="string|null">供相关 API 使用的文件标识符。</ResponseField>
