BATCHES

Create a Batch

Create and execute a batch from an uploaded file of requests.

POST/v1/batches

Authorization

Authorizationstringheaderrequired

Bearer token — your API key. Example: Bearer sk-...

Request body

multipart/form-data
input_file_idstringrequired

The ID of an uploaded file that contains requests for the batch. Must have purpose "batch".

endpoint"/v1/chat/completions" | "/v1/embeddings" | "/v1/responses"required

The endpoint to use for all requests in the batch.

/v1/chat/completions/v1/embeddings/v1/responses
completion_window"24h"

The time frame within which the batch should be processed. Currently only "24h" is supported.

24h
metadataobject

Optional metadata as key-value pairs. Maximum 16 pairs.

Response

idstringrequired

The batch ID (e.g. "batch_abc123").

object"batch"required

Object type — always "batch".

endpointstringrequired

The API endpoint used for requests in this batch.

errorsanyrequired

Validation or processing errors, if any.

input_file_idstringrequired

The ID of the input file for this batch.

completion_windowstringrequired

The time window for batch completion.

status"validating" | "failed" | "in_progress" | "finalizing" | "completed" | "expired" | "cancelling" | "cancelled"required

The current status of the batch.

validatingfailedin_progressfinalizingcompletedexpiredcancellingcancelled
output_file_idstringrequired

The ID of the output file with successful results.

error_file_idstringrequired

The ID of the file containing error results.

created_atintegerrequired

Unix timestamp of when the batch was created.

in_progress_atintegerrequired

Unix timestamp of when processing started.

expires_atintegerrequired

Unix timestamp of when the batch expires.

finalizing_atintegerrequired

Unix timestamp of when finalization started.

completed_atintegerrequired

Unix timestamp of when the batch completed.

failed_atintegerrequired

Unix timestamp of when the batch failed.

expired_atintegerrequired

Unix timestamp of when the batch expired.

cancelling_atintegerrequired

Unix timestamp of when cancellation started.

cancelled_atintegerrequired

Unix timestamp of when the batch was cancelled.

request_countsobjectrequired

Request processing counts.

metadataobjectrequired

User-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);

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