java/resources/batches/methods/cancel/index.md +0 −268 deleted
File Deleted View Diff
1## Cancel batch
2
3`Batch batches().cancel(BatchCancelParamsparams = BatchCancelParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`
4
5**post** `/batches/{batch_id}/cancel`
6
7Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file.
8
9### Parameters
10
11- `BatchCancelParams params`
12
13 - `Optional<String> batchId`
14
15### Returns
16
17- `class Batch:`
18
19 - `String id`
20
21 - `String completionWindow`
22
23 The time frame within which the batch should be processed.
24
25 - `long createdAt`
26
27 The Unix timestamp (in seconds) for when the batch was created.
28
29 - `String endpoint`
30
31 The OpenAI API endpoint used by the batch.
32
33 - `String inputFileId`
34
35 The ID of the input file for the batch.
36
37 - `JsonValue; object_ "batch"constant`
38
39 The object type, which is always `batch`.
40
41 - `BATCH("batch")`
42
43 - `Status status`
44
45 The current status of the batch.
46
47 - `VALIDATING("validating")`
48
49 - `FAILED("failed")`
50
51 - `IN_PROGRESS("in_progress")`
52
53 - `FINALIZING("finalizing")`
54
55 - `COMPLETED("completed")`
56
57 - `EXPIRED("expired")`
58
59 - `CANCELLING("cancelling")`
60
61 - `CANCELLED("cancelled")`
62
63 - `Optional<Long> cancelledAt`
64
65 The Unix timestamp (in seconds) for when the batch was cancelled.
66
67 - `Optional<Long> cancellingAt`
68
69 The Unix timestamp (in seconds) for when the batch started cancelling.
70
71 - `Optional<Long> completedAt`
72
73 The Unix timestamp (in seconds) for when the batch was completed.
74
75 - `Optional<String> errorFileId`
76
77 The ID of the file containing the outputs of requests with errors.
78
79 - `Optional<Errors> errors`
80
81 - `Optional<List<BatchError>> data`
82
83 - `Optional<String> code`
84
85 An error code identifying the error type.
86
87 - `Optional<Long> line`
88
89 The line number of the input file where the error occurred, if applicable.
90
91 - `Optional<String> message`
92
93 A human-readable message providing more details about the error.
94
95 - `Optional<String> param`
96
97 The name of the parameter that caused the error, if applicable.
98
99 - `Optional<String> object_`
100
101 The object type, which is always `list`.
102
103 - `Optional<Long> expiredAt`
104
105 The Unix timestamp (in seconds) for when the batch expired.
106
107 - `Optional<Long> expiresAt`
108
109 The Unix timestamp (in seconds) for when the batch will expire.
110
111 - `Optional<Long> failedAt`
112
113 The Unix timestamp (in seconds) for when the batch failed.
114
115 - `Optional<Long> finalizingAt`
116
117 The Unix timestamp (in seconds) for when the batch started finalizing.
118
119 - `Optional<Long> inProgressAt`
120
121 The Unix timestamp (in seconds) for when the batch started processing.
122
123 - `Optional<Metadata> metadata`
124
125 Set of 16 key-value pairs that can be attached to an object. This can be
126 useful for storing additional information about the object in a structured
127 format, and querying for objects via API or the dashboard.
128
129 Keys are strings with a maximum length of 64 characters. Values are strings
130 with a maximum length of 512 characters.
131
132 - `Optional<String> model`
133
134 Model ID used to process the batch, like `gpt-5-2025-08-07`. OpenAI
135 offers a wide range of models with different capabilities, performance
136 characteristics, and price points. Refer to the [model
137 guide](https://platform.openai.com/docs/models) to browse and compare available models.
138
139 - `Optional<String> outputFileId`
140
141 The ID of the file containing the outputs of successfully executed requests.
142
143 - `Optional<BatchRequestCounts> requestCounts`
144
145 The request counts for different statuses within the batch.
146
147 - `long completed`
148
149 Number of requests that have been completed successfully.
150
151 - `long failed`
152
153 Number of requests that have failed.
154
155 - `long total`
156
157 Total number of requests in the batch.
158
159 - `Optional<BatchUsage> usage`
160
161 Represents token usage details including input tokens, output tokens, a
162 breakdown of output tokens, and the total tokens used. Only populated on
163 batches created after September 7, 2025.
164
165 - `long inputTokens`
166
167 The number of input tokens.
168
169 - `InputTokensDetails inputTokensDetails`
170
171 A detailed breakdown of the input tokens.
172
173 - `long cachedTokens`
174
175 The number of tokens that were retrieved from the cache. [More on
176 prompt caching](https://platform.openai.com/docs/guides/prompt-caching).
177
178 - `long outputTokens`
179
180 The number of output tokens.
181
182 - `OutputTokensDetails outputTokensDetails`
183
184 A detailed breakdown of the output tokens.
185
186 - `long reasoningTokens`
187
188 The number of reasoning tokens.
189
190 - `long totalTokens`
191
192 The total number of tokens used.
193
194### Example
195
196```java
197package com.openai.example;
198
199import com.openai.client.OpenAIClient;
200import com.openai.client.okhttp.OpenAIOkHttpClient;
201import com.openai.models.batches.Batch;
202import com.openai.models.batches.BatchCancelParams;
203
204public final class Main {
205 private Main() {}
206
207 public static void main(String[] args) {
208 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
209
210 Batch batch = client.batches().cancel("batch_id");
211 }
212}
213```
214
215#### Response
216
217```json
218{
219 "id": "id",
220 "completion_window": "completion_window",
221 "created_at": 0,
222 "endpoint": "endpoint",
223 "input_file_id": "input_file_id",
224 "object": "batch",
225 "status": "validating",
226 "cancelled_at": 0,
227 "cancelling_at": 0,
228 "completed_at": 0,
229 "error_file_id": "error_file_id",
230 "errors": {
231 "data": [
232 {
233 "code": "code",
234 "line": 0,
235 "message": "message",
236 "param": "param"
237 }
238 ],
239 "object": "object"
240 },
241 "expired_at": 0,
242 "expires_at": 0,
243 "failed_at": 0,
244 "finalizing_at": 0,
245 "in_progress_at": 0,
246 "metadata": {
247 "foo": "string"
248 },
249 "model": "model",
250 "output_file_id": "output_file_id",
251 "request_counts": {
252 "completed": 0,
253 "failed": 0,
254 "total": 0
255 },
256 "usage": {
257 "input_tokens": 0,
258 "input_tokens_details": {
259 "cached_tokens": 0
260 },
261 "output_tokens": 0,
262 "output_tokens_details": {
263 "reasoning_tokens": 0
264 },
265 "total_tokens": 0
266 }
267}
268```