BATCHES

Cancel a Batch

Cancel an in-progress batch. The batch status will transition to "cancelling" and eventually "cancelled".

POST/v1/batches/{batch_id}/cancel

Authorization

Authorizationstringheaderrequired

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

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.cancel("batch_abc123def456");

console.log(batch.status); // "cancelling"

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": "cancelling",
  "output_file_id": null,
  "error_file_id": null,
  "created_at": 1711756800,
  "in_progress_at": 1711756810,
  "expires_at": 1711843200,
  "finalizing_at": null,
  "completed_at": null,
  "failed_at": null,
  "expired_at": null,
  "cancelling_at": 1711758600,
  "cancelled_at": null,
  "request_counts": {
    "total": 100,
    "completed": 45,
    "failed": 0
  },
  "metadata": {}
}