跳转到主要内容
POST
/
openai
/
v1
/
batches
创建批处理任务
curl --request POST \
  --url https://api.ppio.com/openai/v1/batches \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: <content-type>' \
  --data '
{
  "input_file_id": "<string>",
  "endpoint": "<string>",
  "completion_window": "<string>"
}
'
import requests

url = "https://api.ppio.com/openai/v1/batches"

payload = {
"input_file_id": "<string>",
"endpoint": "<string>",
"completion_window": "<string>"
}
headers = {
"Content-Type": "<content-type>",
"Authorization": "<authorization>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'Content-Type': '<content-type>', Authorization: '<authorization>'},
body: JSON.stringify({input_file_id: '<string>', endpoint: '<string>', completion_window: '<string>'})
};

fetch('https://api.ppio.com/openai/v1/batches', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ppio.com/openai/v1/batches",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'input_file_id' => '<string>',
'endpoint' => '<string>',
'completion_window' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.ppio.com/openai/v1/batches"

payload := strings.NewReader("{\n \"input_file_id\": \"<string>\",\n \"endpoint\": \"<string>\",\n \"completion_window\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Authorization", "<authorization>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.ppio.com/openai/v1/batches")
.header("Content-Type", "<content-type>")
.header("Authorization", "<authorization>")
.body("{\n \"input_file_id\": \"<string>\",\n \"endpoint\": \"<string>\",\n \"completion_window\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.ppio.com/openai/v1/batches")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = '<content-type>'
request["Authorization"] = '<authorization>'
request.body = "{\n \"input_file_id\": \"<string>\",\n \"endpoint\": \"<string>\",\n \"completion_window\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "<string>",
  "object": "<string>",
  "endpoint": "<string>",
  "input_file_id": "<string>",
  "output_file_id": "<string>",
  "error_file_id": "<string>",
  "completion_window": "<string>",
  "in_progress_at": {},
  "expires_at": {},
  "finalizing_at": {},
  "completed_at": {},
  "failed_at": {},
  "expired_at": {},
  "cancelling_at": {},
  "cancelled_at": {},
  "status": "<string>",
  "errors": "<string>",
  "version": 123,
  "created_at": "<string>",
  "updated_at": {},
  "created_by": "<string>",
  "created_by_key_id": "<string>",
  "remark": "<string>",
  "total": 123,
  "completed": 123,
  "failed": 123,
  "metadata": {},
  "request_counts": {
    "total": 123,
    "completed": 123,
    "failed": 123
  }
}
成功 上传文件 后,使用该文件的 ID 来发起一个批处理任务。请注意,完成窗口固定为 48 小时,当前不可修改。

请求头

Content-Type
string
必填
枚举值: application/json
Authorization
string
必填
Bearer 身份验证格式,例如:Bearer {{API 密钥}}。

请求体

input_file_id
string
必填
已上传的、包含批处理请求的输入文件 ID。
endpoint
string
必填
批处理所使用的端点。可用端点为 /v1/chat/completions/v1/completions
为了兼容 OpenAI API,请将 endpoint 参数设置为 /v1/chat/completions/v1/completions
completion_window
string
批处理完成的时间窗口。当前固定为 48h,不可调整。

响应

id
string
必填
批处理任务的唯一标识符。
object
string
必填
对象类型,恒为 batch
endpoint
string
必填
批处理任务用于处理请求的 API 端点。
input_file_id
string
必填
包含批处理请求的输入文件 ID。
output_file_id
string
必填
包含批处理结果的输出文件 ID。在批处理完成之前为空。
error_file_id
string
必填
包含批处理过程中发生的错误的错误文件 ID。在出现错误之前为空。
completion_window
string
必填
批处理完成的时间窗口。当前固定为 48h
in_progress_at
string | null
批处理开始处理的时间戳。若尚未开始则为 null。
expires_at
string | null
批处理到期的时间戳。若未设置则为 null。
finalizing_at
string | null
批处理开始进入最终化阶段的时间戳。若尚未进入则为 null。
completed_at
string | null
批处理完成的时间戳。若尚未完成则为 null。
failed_at
string | null
批处理失败的时间戳。若未失败则为 null。
expired_at
string | null
批处理过期的时间戳。若未过期则为 null。
cancelling_at
string | null
批处理开始取消的时间戳。若未在取消中则为 null。
cancelled_at
string | null
批处理被取消的时间戳。若未被取消则为 null。
status
string
必填
批处理任务的当前状态。可用状态:
  • VALIDATING - 在批处理开始前正在验证输入文件
  • PROGRESS - 批处理进行中
  • COMPLETED - 批处理成功完成
  • FAILED - 批处理失败
  • EXPIRED - 批处理超过截止时间
  • CANCELLING - 正在取消批处理
  • CANCELLED - 批处理已取消
errors
string
批处理过程中发生错误时的错误信息。
version
integer
必填
批处理任务的版本号。
created_at
string
必填
批处理任务的创建时间戳。
updated_at
string | null
批处理任务最近一次更新的时间戳。若从未更新则为 null。
created_by
string
必填
创建该批处理任务的用户唯一标识符。
created_by_key_id
string
必填
用于创建该批处理任务的 API Key ID。
remark
string
批处理任务的可选备注信息。
total
integer
必填
批处理中的请求总数。
completed
integer
必填
批处理中已完成的请求数量。
failed
integer
必填
批处理中失败的请求数量。
metadata
object | null
与批处理任务关联的附加元数据。若无则为 null。
request_counts
object
必填
请求计数的详细信息。
最后修改于 2026年1月12日