BATCHES
Create a Batch
Create and execute a batch from an uploaded file of requests.
Authorization
AuthorizationstringheaderrequiredBearer token — your API key. Example: Bearer sk-...
Request body
multipart/form-datainput_file_idstringrequiredThe ID of an uploaded file that contains requests for the batch. Must have purpose "batch".
endpoint"/v1/chat/completions" | "/v1/embeddings" | "/v1/responses"requiredThe endpoint to use for all requests in the batch.
/v1/chat/completions/v1/embeddings/v1/responsescompletion_window"24h"The time frame within which the batch should be processed. Currently only "24h" is supported.
24hmetadataobjectOptional metadata as key-value pairs. Maximum 16 pairs.
Response
idstringrequiredThe batch ID (e.g. "batch_abc123").
object"batch"requiredObject type — always "batch".
endpointstringrequiredThe API endpoint used for requests in this batch.
errorsanyrequiredValidation or processing errors, if any.
input_file_idstringrequiredThe ID of the input file for this batch.
completion_windowstringrequiredThe time window for batch completion.
status"validating" | "failed" | "in_progress" | "finalizing" | "completed" | "expired" | "cancelling" | "cancelled"requiredThe current status of the batch.
validatingfailedin_progressfinalizingcompletedexpiredcancellingcancelledoutput_file_idstringrequiredThe ID of the output file with successful results.
error_file_idstringrequiredThe ID of the file containing error results.
created_atintegerrequiredUnix timestamp of when the batch was created.
in_progress_atintegerrequiredUnix timestamp of when processing started.
expires_atintegerrequiredUnix timestamp of when the batch expires.
finalizing_atintegerrequiredUnix timestamp of when finalization started.
completed_atintegerrequiredUnix timestamp of when the batch completed.
failed_atintegerrequiredUnix timestamp of when the batch failed.
expired_atintegerrequiredUnix timestamp of when the batch expired.
cancelling_atintegerrequiredUnix timestamp of when cancellation started.
cancelled_atintegerrequiredUnix timestamp of when the batch was cancelled.
request_countsobjectrequiredRequest processing counts.
metadataobjectrequiredUser-provided metadata key-value pairs.
Request
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-scx-api-key",
baseURL: "https://api.scx.ai/v1",
});
const batch = await client.batches.create({
input_file_id: "file-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
endpoint: "/v1/chat/completions",
completion_window: "24h",
});
console.log(batch.id, batch.status);import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-scx-api-key",
baseURL: "https://api.scx.ai/v1",
});
const batch = await client.batches.create({
input_file_id: "file-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
endpoint: "/v1/chat/completions",
completion_window: "24h",
});
console.log(batch.id, batch.status);Response
{
"id": "batch_abc123def456",
"object": "batch",
"endpoint": "/v1/chat/completions",
"errors": null,
"input_file_id": "file-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"completion_window": "24h",
"status": "validating",
"output_file_id": null,
"error_file_id": null,
"created_at": 1711756800,
"in_progress_at": null,
"expires_at": null,
"finalizing_at": null,
"completed_at": null,
"failed_at": null,
"expired_at": null,
"cancelling_at": null,
"cancelled_at": null,
"request_counts": {
"total": 0,
"completed": 0,
"failed": 0
},
"metadata": {
"description": "evaluation run"
}
}{
"id": "batch_abc123def456",
"object": "batch",
"endpoint": "/v1/chat/completions",
"errors": null,
"input_file_id": "file-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"completion_window": "24h",
"status": "validating",
"output_file_id": null,
"error_file_id": null,
"created_at": 1711756800,
"in_progress_at": null,
"expires_at": null,
"finalizing_at": null,
"completed_at": null,
"failed_at": null,
"expired_at": null,
"cancelling_at": null,
"cancelled_at": null,
"request_counts": {
"total": 0,
"completed": 0,
"failed": 0
},
"metadata": {
"description": "evaluation run"
}
}