创建 batch

POST/v1/batches

基于已上传的 JSONL 输入文件(purpose=batch)创建异步 batch 作业。平台会校验文件、要求全文件单一 body.model、锁定一条上游路由并入队提交。

MVP 仅支持 endpoint=/v1/chat/completionscompletion_window=24h

JSONL 格式与约束见 批量任务

Authentication

Authorization Bearer

Request Body

input_file_idstringrequired

File ID from POST /v1/files with purpose=batch.

endpointstring

Must be /v1/chat/completions (default if omitted).

completion_windowstring

Must be 24h (default if omitted).

callback_urlstring

Optional HTTPS URL for terminal-state webhook. Overrides account default batch webhook when set.

metadataobject

Optional key/value metadata stored on the batch object.

Response

idstring

Batch ID (batch_ prefix).

objectstring

batch

endpointstring

/v1/chat/completions

statusstring

validating, then in_progress, etc.

Available options: validating failed in_progress finalizing completed expired cancelling cancelled

input_file_idstring

Input file ID.

output_file_idstring

Set when completed.

error_file_idstring

Set when partial failures or errors are written.

completion_windowstring

24h

request_countsobject

total, completed, failed counts when available.

created_atinteger

Unix timestamp.

expires_atinteger

Unix timestamp (created + 24h).

metadataobject

Echo of request metadata.

Common errors

batch_multiple_modelsMore than one distinct body.model in the input file.
batch_invalid_jsonlMalformed line or invalid fields.
batch_model_not_supportedModel has no batch-capable provider route.
batch_routing_unavailableNo active SKU for the model.

请求

1curl -X POST https://api.token360.ai/v1/batches \
2  -H "Authorization: Bearer sk-your-api-key" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "input_file_id": "file_abc123",
6    "endpoint": "/v1/chat/completions",
7    "completion_window": "24h",
8    "metadata": {"job": "nightly"}
9  }'

响应

JSON
1{
2  "id": "batch_01abc",
3  "object": "batch",
4  "endpoint": "/v1/chat/completions",
5  "status": "validating",
6  "input_file_id": "file_abc123",
7  "output_file_id": null,
8  "error_file_id": null,
9  "completion_window": "24h",
10  "request_counts": null,
11  "created_at": 1710000000,
12  "expires_at": 1710086400,
13  "metadata": {"job": "nightly"}
14}
此页面对您有帮助吗?