Repository Public
1> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.23## Cancel batch45**post** `/batches/{batch_id}/cancel`67Cancels 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.89### Path Parameters1011- `batch_id: string`1213### Returns1415- `Batch object { id, completion_window, created_at, 19 more }`1617 - `id: string`1819 - `completion_window: string`2021 The time frame within which the batch should be processed.2223 - `created_at: number`2425 The Unix timestamp (in seconds) for when the batch was created.2627 - `endpoint: string`2829 The OpenAI API endpoint used by the batch.3031 - `input_file_id: string`3233 The ID of the input file for the batch.3435 - `object: "batch"`3637 The object type, which is always `batch`.3839 - `"batch"`4041 - `status: "validating" or "failed" or "in_progress" or 5 more`4243 The current status of the batch.4445 - `"validating"`4647 - `"failed"`4849 - `"in_progress"`5051 - `"finalizing"`5253 - `"completed"`5455 - `"expired"`5657 - `"cancelling"`5859 - `"cancelled"`6061 - `cancelled_at: optional number`6263 The Unix timestamp (in seconds) for when the batch was cancelled.6465 - `cancelling_at: optional number`6667 The Unix timestamp (in seconds) for when the batch started cancelling.6869 - `completed_at: optional number`7071 The Unix timestamp (in seconds) for when the batch was completed.7273 - `error_file_id: optional string`7475 The ID of the file containing the outputs of requests with errors.7677 - `errors: optional object { data, object }`7879 - `data: optional array of BatchError`8081 - `code: optional string`8283 An error code identifying the error type.8485 - `line: optional number or null`8687 The line number of the input file where the error occurred, if applicable.8889 - `message: optional string`9091 A human-readable message providing more details about the error.9293 - `param: optional string or null`9495 The name of the parameter that caused the error, if applicable.9697 - `object: optional string`9899 The object type, which is always `list`.100101 - `expired_at: optional number`102103 The Unix timestamp (in seconds) for when the batch expired.104105 - `expires_at: optional number`106107 The Unix timestamp (in seconds) for when the batch will expire.108109 - `failed_at: optional number`110111 The Unix timestamp (in seconds) for when the batch failed.112113 - `finalizing_at: optional number`114115 The Unix timestamp (in seconds) for when the batch started finalizing.116117 - `in_progress_at: optional number`118119 The Unix timestamp (in seconds) for when the batch started processing.120121 - `metadata: optional Metadata or null`122123 Set of 16 key-value pairs that can be attached to an object. This can be124 useful for storing additional information about the object in a structured125 format, and querying for objects via API or the dashboard.126127 Keys are strings with a maximum length of 64 characters. Values are strings128 with a maximum length of 512 characters.129130 - `model: optional string`131132 Model ID used to process the batch, like `gpt-6-astra`. OpenAI133 offers a wide range of models with different capabilities, performance134 characteristics, and price points. Refer to the [model135 guide](/api/docs/models) to browse and compare available models.136137 - `output_file_id: optional string`138139 The ID of the file containing the outputs of successfully executed requests.140141 - `request_counts: optional BatchRequestCounts`142143 The request counts for different statuses within the batch.144145 - `completed: number`146147 Number of requests that have been completed successfully.148149 - `failed: number`150151 Number of requests that have failed.152153 - `total: number`154155 Total number of requests in the batch.156157 - `usage: optional BatchUsage`158159 Represents token usage details including input tokens, output tokens, a160 breakdown of output tokens, and the total tokens used. Only populated on161 batches created after September 7, 2025.162163 - `input_tokens: number`164165 The number of input tokens.166167 - `input_tokens_details: object { cached_tokens }`168169 A detailed breakdown of the input tokens.170171 - `cached_tokens: number`172173 The number of tokens that were retrieved from the cache. [More on174 prompt caching](/api/docs/guides/prompt-caching).175176 - `output_tokens: number`177178 The number of output tokens.179180 - `output_tokens_details: object { reasoning_tokens }`181182 A detailed breakdown of the output tokens.183184 - `reasoning_tokens: number`185186 The number of reasoning tokens.187188 - `total_tokens: number`189190 The total number of tokens used.191192### Example193194```http195curl https://api.openai.com/v1/batches/$BATCH_ID/cancel \196 -X POST \197 -H "Authorization: Bearer $OPENAI_API_KEY"198```199200#### Response201202```json203{204 "id": "id",205 "completion_window": "completion_window",206 "created_at": 0,207 "endpoint": "endpoint",208 "input_file_id": "input_file_id",209 "object": "batch",210 "status": "validating",211 "cancelled_at": 0,212 "cancelling_at": 0,213 "completed_at": 0,214 "error_file_id": "error_file_id",215 "errors": {216 "data": [217 {218 "code": "code",219 "line": 0,220 "message": "message",221 "param": "param"222 }223 ],224 "object": "object"225 },226 "expired_at": 0,227 "expires_at": 0,228 "failed_at": 0,229 "finalizing_at": 0,230 "in_progress_at": 0,231 "metadata": {232 "foo": "string"233 },234 "model": "model",235 "output_file_id": "output_file_id",236 "request_counts": {237 "completed": 0,238 "failed": 0,239 "total": 0240 },241 "usage": {242 "input_tokens": 0,243 "input_tokens_details": {244 "cached_tokens": 0245 },246 "output_tokens": 0,247 "output_tokens_details": {248 "reasoning_tokens": 0249 },250 "total_tokens": 0251 }252}253```254255### Example256257```http258curl https://api.openai.com/v1/batches/batch_abc123/cancel \259 -H "Authorization: Bearer $OPENAI_API_KEY" \260 -H "Content-Type: application/json" \261 -X POST262```263264#### Response265266```json267{268 "id": "batch_abc123",269 "object": "batch",270 "endpoint": "/v1/chat/completions",271 "errors": null,272 "input_file_id": "file-abc123",273 "completion_window": "24h",274 "status": "cancelling",275 "output_file_id": null,276 "error_file_id": null,277 "created_at": 1711471533,278 "in_progress_at": 1711471538,279 "expires_at": 1711557933,280 "finalizing_at": null,281 "completed_at": null,282 "failed_at": null,283 "expired_at": null,284 "cancelling_at": 1711475133,285 "cancelled_at": null,286 "request_counts": {287 "total": 100,288 "completed": 23,289 "failed": 1290 },291 "metadata": {292 "customer_id": "user_123456789",293 "batch_description": "Nightly eval job",294 }295}296```297