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## Create batch45**post** `/batches`67Creates and executes a batch from an uploaded file of requests89### Body Parameters1011- `completion_window: "24h"`1213 The time frame within which the batch should be processed. Currently only `24h` is supported.1415 - `"24h"`1617- `endpoint: "/v1/responses" or "/v1/chat/completions" or "/v1/embeddings" or 5 more`1819 The endpoint to be used for all requests in the batch. Currently `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, `/v1/images/generations`, `/v1/images/edits`, and `/v1/videos` are supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs across all requests in the batch.2021 - `"/v1/responses"`2223 - `"/v1/chat/completions"`2425 - `"/v1/embeddings"`2627 - `"/v1/completions"`2829 - `"/v1/moderations"`3031 - `"/v1/images/generations"`3233 - `"/v1/images/edits"`3435 - `"/v1/videos"`3637- `input_file_id: string`3839 The ID of an uploaded file that contains requests for the new batch.4041 See [upload file](/api/reference/resources/files/methods/create) for how to upload a file.4243 Your input file must be formatted as a [JSONL file](/api/docs/guides/batch#1-prepare-your-batch-file), and must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up to 200 MB in size.4445- `metadata: optional Metadata or null`4647 Set of 16 key-value pairs that can be attached to an object. This can be48 useful for storing additional information about the object in a structured49 format, and querying for objects via API or the dashboard.5051 Keys are strings with a maximum length of 64 characters. Values are strings52 with a maximum length of 512 characters.5354- `output_expires_after: optional object { anchor, seconds }`5556 The expiration policy for the output and/or error file that are generated for a batch.5758 - `anchor: "created_at"`5960 Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`. Note that the anchor is the file creation time, not the time the batch is created.6162 - `"created_at"`6364 - `seconds: number`6566 The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).6768### Returns6970- `Batch object { id, completion_window, created_at, 19 more }`7172 - `id: string`7374 - `completion_window: string`7576 The time frame within which the batch should be processed.7778 - `created_at: number`7980 The Unix timestamp (in seconds) for when the batch was created.8182 - `endpoint: string`8384 The OpenAI API endpoint used by the batch.8586 - `input_file_id: string`8788 The ID of the input file for the batch.8990 - `object: "batch"`9192 The object type, which is always `batch`.9394 - `"batch"`9596 - `status: "validating" or "failed" or "in_progress" or 5 more`9798 The current status of the batch.99100 - `"validating"`101102 - `"failed"`103104 - `"in_progress"`105106 - `"finalizing"`107108 - `"completed"`109110 - `"expired"`111112 - `"cancelling"`113114 - `"cancelled"`115116 - `cancelled_at: optional number`117118 The Unix timestamp (in seconds) for when the batch was cancelled.119120 - `cancelling_at: optional number`121122 The Unix timestamp (in seconds) for when the batch started cancelling.123124 - `completed_at: optional number`125126 The Unix timestamp (in seconds) for when the batch was completed.127128 - `error_file_id: optional string`129130 The ID of the file containing the outputs of requests with errors.131132 - `errors: optional object { data, object }`133134 - `data: optional array of BatchError`135136 - `code: optional string`137138 An error code identifying the error type.139140 - `line: optional number or null`141142 The line number of the input file where the error occurred, if applicable.143144 - `message: optional string`145146 A human-readable message providing more details about the error.147148 - `param: optional string or null`149150 The name of the parameter that caused the error, if applicable.151152 - `object: optional string`153154 The object type, which is always `list`.155156 - `expired_at: optional number`157158 The Unix timestamp (in seconds) for when the batch expired.159160 - `expires_at: optional number`161162 The Unix timestamp (in seconds) for when the batch will expire.163164 - `failed_at: optional number`165166 The Unix timestamp (in seconds) for when the batch failed.167168 - `finalizing_at: optional number`169170 The Unix timestamp (in seconds) for when the batch started finalizing.171172 - `in_progress_at: optional number`173174 The Unix timestamp (in seconds) for when the batch started processing.175176 - `metadata: optional Metadata or null`177178 Set of 16 key-value pairs that can be attached to an object. This can be179 useful for storing additional information about the object in a structured180 format, and querying for objects via API or the dashboard.181182 Keys are strings with a maximum length of 64 characters. Values are strings183 with a maximum length of 512 characters.184185 - `model: optional string`186187 Model ID used to process the batch, like `gpt-6-astra`. OpenAI188 offers a wide range of models with different capabilities, performance189 characteristics, and price points. Refer to the [model190 guide](/api/docs/models) to browse and compare available models.191192 - `output_file_id: optional string`193194 The ID of the file containing the outputs of successfully executed requests.195196 - `request_counts: optional BatchRequestCounts`197198 The request counts for different statuses within the batch.199200 - `completed: number`201202 Number of requests that have been completed successfully.203204 - `failed: number`205206 Number of requests that have failed.207208 - `total: number`209210 Total number of requests in the batch.211212 - `usage: optional BatchUsage`213214 Represents token usage details including input tokens, output tokens, a215 breakdown of output tokens, and the total tokens used. Only populated on216 batches created after September 7, 2025.217218 - `input_tokens: number`219220 The number of input tokens.221222 - `input_tokens_details: object { cached_tokens }`223224 A detailed breakdown of the input tokens.225226 - `cached_tokens: number`227228 The number of tokens that were retrieved from the cache. [More on229 prompt caching](/api/docs/guides/prompt-caching).230231 - `output_tokens: number`232233 The number of output tokens.234235 - `output_tokens_details: object { reasoning_tokens }`236237 A detailed breakdown of the output tokens.238239 - `reasoning_tokens: number`240241 The number of reasoning tokens.242243 - `total_tokens: number`244245 The total number of tokens used.246247### Example248249```http250curl https://api.openai.com/v1/batches \251 -H 'Content-Type: application/json' \252 -H "Authorization: Bearer $OPENAI_API_KEY" \253 -d '{254 "completion_window": "24h",255 "endpoint": "/v1/responses",256 "input_file_id": "input_file_id"257 }'258```259260#### Response261262```json263{264 "id": "id",265 "completion_window": "completion_window",266 "created_at": 0,267 "endpoint": "endpoint",268 "input_file_id": "input_file_id",269 "object": "batch",270 "status": "validating",271 "cancelled_at": 0,272 "cancelling_at": 0,273 "completed_at": 0,274 "error_file_id": "error_file_id",275 "errors": {276 "data": [277 {278 "code": "code",279 "line": 0,280 "message": "message",281 "param": "param"282 }283 ],284 "object": "object"285 },286 "expired_at": 0,287 "expires_at": 0,288 "failed_at": 0,289 "finalizing_at": 0,290 "in_progress_at": 0,291 "metadata": {292 "foo": "string"293 },294 "model": "model",295 "output_file_id": "output_file_id",296 "request_counts": {297 "completed": 0,298 "failed": 0,299 "total": 0300 },301 "usage": {302 "input_tokens": 0,303 "input_tokens_details": {304 "cached_tokens": 0305 },306 "output_tokens": 0,307 "output_tokens_details": {308 "reasoning_tokens": 0309 },310 "total_tokens": 0311 }312}313```314315### Example316317```http318curl https://api.openai.com/v1/batches \319 -H "Authorization: Bearer $OPENAI_API_KEY" \320 -H "Content-Type: application/json" \321 -d '{322 "input_file_id": "file-abc123",323 "endpoint": "/v1/chat/completions",324 "completion_window": "24h"325 }'326```327328#### Response329330```json331{332 "id": "batch_abc123",333 "object": "batch",334 "endpoint": "/v1/chat/completions",335 "errors": null,336 "input_file_id": "file-abc123",337 "completion_window": "24h",338 "status": "validating",339 "output_file_id": null,340 "error_file_id": null,341 "created_at": 1711471533,342 "in_progress_at": null,343 "expires_at": null,344 "finalizing_at": null,345 "completed_at": null,346 "failed_at": null,347 "expired_at": null,348 "cancelling_at": null,349 "cancelled_at": null,350 "request_counts": {351 "total": 0,352 "completed": 0,353 "failed": 0354 },355 "metadata": {356 "customer_id": "user_123456789",357 "batch_description": "Nightly eval job",358 }359}360```361