SpyBara
Go Premium

java/resources/batches/methods/cancel/index.md 2026-07-07 08:02 UTC to 2026-07-09 20:58 UTC

229 added, 0 removed.

2026
Wed 15 02:58 Tue 14 06:58 Mon 13 15:59 Sun 12 06:58 Fri 10 23:02 Thu 9 20:58 Tue 7 08:02

Cancel batch

Batch batches().cancel(BatchCancelParamsparams = BatchCancelParams.none(), RequestOptionsrequestOptions = RequestOptions.none())

post /batches/{batch_id}/cancel

Cancel batch

Parameters

  • BatchCancelParams params

    • Optional<String> batchId

Returns

  • class Batch:

    • String id

    • String completionWindow

      The time frame within which the batch should be processed.

    • long createdAt

      The Unix timestamp (in seconds) for when the batch was created.

    • String endpoint

      The OpenAI API endpoint used by the batch.

    • String inputFileId

      The ID of the input file for the batch.

    • JsonValue; object_ "batch"constant

      The object type, which is always batch.

      • BATCH("batch")
    • Status status

      The current status of the batch.

      • VALIDATING("validating")

      • FAILED("failed")

      • IN_PROGRESS("in_progress")

      • FINALIZING("finalizing")

      • COMPLETED("completed")

      • EXPIRED("expired")

      • CANCELLING("cancelling")

      • CANCELLED("cancelled")

    • Optional<Long> cancelledAt

      The Unix timestamp (in seconds) for when the batch was cancelled.

    • Optional<Long> cancellingAt

      The Unix timestamp (in seconds) for when the batch started cancelling.

    • Optional<Long> completedAt

      The Unix timestamp (in seconds) for when the batch was completed.

    • Optional<String> errorFileId

      The ID of the file containing the outputs of requests with errors.

    • Optional<Errors> errors

      • Optional<List<JsonValue>> data

      • Optional<String> object_

        The object type, which is always list.

    • Optional<Long> expiredAt

      The Unix timestamp (in seconds) for when the batch expired.

    • Optional<Long> expiresAt

      The Unix timestamp (in seconds) for when the batch will expire.

    • Optional<Long> failedAt

      The Unix timestamp (in seconds) for when the batch failed.

    • Optional<Long> finalizingAt

      The Unix timestamp (in seconds) for when the batch started finalizing.

    • Optional<Long> inProgressAt

      The Unix timestamp (in seconds) for when the batch started processing.

    • Optional<Metadata> metadata

      Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

      Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

    • Optional<String> model

      Model ID used to process the batch, like gpt-5-2025-08-07. OpenAI offers a wide range of models with different capabilities, performance characteristics, and price points. Refer to the model guide to browse and compare available models.

    • Optional<String> outputFileId

      The ID of the file containing the outputs of successfully executed requests.

    • Optional<JsonValue> requestCounts

    • Optional<BatchUsage> usage

      Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used. Only populated on batches created after September 7, 2025.

      • long inputTokens

        The number of input tokens.

      • InputTokensDetails inputTokensDetails

        A detailed breakdown of the input tokens.

      • long outputTokens

        The number of output tokens.

      • OutputTokensDetails outputTokensDetails

        A detailed breakdown of the output tokens.

        • long reasoningTokens

          The number of reasoning tokens.

      • long totalTokens

        The total number of tokens used.

Example

package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.batches.Batch;
import com.openai.models.batches.BatchCancelParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        Batch batch = client.batches().cancel("batch_id");
    }
}

Response

{
  "id": "id",
  "completion_window": "completion_window",
  "created_at": 0,
  "endpoint": "endpoint",
  "input_file_id": "input_file_id",
  "object": "batch",
  "status": "validating",
  "cancelled_at": 0,
  "cancelling_at": 0,
  "completed_at": 0,
  "error_file_id": "error_file_id",
  "errors": {
    "data": [
      {}
    ],
    "object": "object"
  },
  "expired_at": 0,
  "expires_at": 0,
  "failed_at": 0,
  "finalizing_at": 0,
  "in_progress_at": 0,
  "metadata": {
    "foo": "string"
  },
  "model": "model",
  "output_file_id": "output_file_id",
  "request_counts": {},
  "usage": {
    "input_tokens": 0,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 0,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 0
  }
}