> For the complete documentation index, see [llms.txt](https://docs.nexos.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexos.ai/gateway-api/batches.md).

# Batches

Create and run large groups of requests asynchronously. Batches are only available for OpenAI models.

## Create batch

> Create and immediately start a batch from a file of requests that was uploaded beforehand.\
> \
> Batches are only available for OpenAI models.

```json
{"openapi":"3.0.0","info":{"title":"Nexos AI Public API Production","version":"1.0.0"},"tags":[{"name":"Batches","description":"Create and run large groups of requests asynchronously. Batches are only available for OpenAI models."}],"servers":[{"url":"https://api.nexos.ai"}],"security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"},"apiKeyHeader":{"type":"apiKey","in":"header","name":"X-Api-Key","description":"Authenticate by sending your nexos API key in the `X-Api-Key` header (e.g. `X-Api-Key: nexos-...` for a user key or `X-Api-Key: nexos-team-...` for a team key). This is an alternative to the `Authorization: Bearer` scheme. If both `X-Nexos-Key` and `X-Api-Key` are sent, `X-Nexos-Key` takes precedence."}},"schemas":{"BatchesRequest":{"type":"object","properties":{"input_file_id":{"type":"string","description":"The ID of an uploaded file that contains requests for the new batch.\n\nYour input file must be formatted as a JSONL file, and must be uploaded with the purpose set to \"batch\". The file can contain up to 50,000 requests, and can be up to 200 MB in size.\n"},"endpoint":{"type":"string","description":"The endpoint to be used for all requests in the batch. Currently `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions` are supported.\n","enum":["/v1/chat/completions","/v1/embeddings","/v1/completions"]},"completion_window":{"type":"string","description":"The time frame within which the batch should be processed. Currently only \"24h\" is supported.\n","enum":["24h"],"default":"24h"},"metadata":{"type":"object","description":"Optional custom metadata for the batch. This can be useful for tracking and organizing batches.\n","additionalProperties":{"type":"string"}}},"required":["input_file_id","endpoint","completion_window"]},"Batch":{"type":"object","description":"A batch object representing a collection of requests processed together.\n","properties":{"id":{"type":"string","description":"The unique identifier of the batch.\n"},"object":{"type":"string","description":"The object type, which is always \"batch\".\n","enum":["batch"]},"endpoint":{"type":"string","description":"The endpoint used for the batch requests.\n","enum":["/v1/chat/completions","/v1/embeddings","/v1/completions"]},"errors":{"type":"object","description":"Details about any errors encountered during batch processing.\n","nullable":true,"properties":{"object":{"type":"string","enum":["list"]},"data":{"type":"array","items":{"type":"object","properties":{"code":{"type":"string","description":"Error code indicating the type of error.\n"},"message":{"type":"string","description":"Human-readable error message.\n"},"param":{"type":"string","nullable":true,"description":"The parameter that caused the error, if applicable.\n"},"line":{"type":"integer","nullable":true,"description":"The line number in the input file where the error occurred.\n"}}}}}},"input_file_id":{"type":"string","description":"The ID of the input file used for the batch.\n"},"completion_window":{"type":"string","description":"The time frame within which the batch should be processed.\n"},"status":{"type":"string","description":"The current status of the batch.\n","enum":["validating","failed","in_progress","finalizing","completed","expired","cancelling","cancelled"]},"output_file_id":{"type":"string","nullable":true,"description":"The ID of the file containing the outputs of the batch requests. This is only available when the batch status is \"completed\".\n"},"error_file_id":{"type":"string","nullable":true,"description":"The ID of the file containing the errors of the batch requests. This is only available when there are errors in the batch.\n"},"created_at":{"type":"integer","description":"The Unix timestamp (in seconds) for when the batch was created.\n"},"in_progress_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch started processing.\n"},"expires_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch will expire.\n"},"finalizing_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch started finalizing.\n"},"completed_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch was completed.\n"},"failed_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch failed.\n"},"expired_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch expired.\n"},"cancelling_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch cancellation was initiated.\n"},"cancelled_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch was cancelled.\n"},"request_counts":{"type":"object","description":"Statistics about the requests in the batch.\n","properties":{"total":{"type":"integer","description":"Total number of requests in the batch.\n"},"completed":{"type":"integer","description":"Number of requests that completed successfully.\n"},"failed":{"type":"integer","description":"Number of requests that failed.\n"}},"required":["total","completed","failed"]},"metadata":{"type":"object","nullable":true,"description":"Set of 16 key-value pairs that can be attached to the batch. This can be useful for storing additional information about the batch in a structured format.\n","additionalProperties":{"type":"string"}}},"required":["id","object","endpoint","input_file_id","completion_window","status","created_at","request_counts"]}},"responses":{"BatchesResponse":{"description":"Batch retrieval response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Batch"}}}}}},"paths":{"/v1/batches":{"post":{"tags":["Batches"],"operationId":"post-batches-v1","summary":"Create batch","description":"Create and immediately start a batch from a file of requests that was uploaded beforehand.\n\nBatches are only available for OpenAI models.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BatchesRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/BatchesResponse"},"400":{"description":"Invalid request data."},"500":{"description":"Server error."}}}}}}
```

## Retrieve batch

> Look up a single batch by its ID, including its current status and metadata.

```json
{"openapi":"3.0.0","info":{"title":"Nexos AI Public API Production","version":"1.0.0"},"tags":[{"name":"Batches","description":"Create and run large groups of requests asynchronously. Batches are only available for OpenAI models."}],"servers":[{"url":"https://api.nexos.ai"}],"security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"},"apiKeyHeader":{"type":"apiKey","in":"header","name":"X-Api-Key","description":"Authenticate by sending your nexos API key in the `X-Api-Key` header (e.g. `X-Api-Key: nexos-...` for a user key or `X-Api-Key: nexos-team-...` for a team key). This is an alternative to the `Authorization: Bearer` scheme. If both `X-Nexos-Key` and `X-Api-Key` are sent, `X-Nexos-Key` takes precedence."}},"responses":{"BatchesResponse":{"description":"Batch retrieval response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Batch"}}}}},"schemas":{"Batch":{"type":"object","description":"A batch object representing a collection of requests processed together.\n","properties":{"id":{"type":"string","description":"The unique identifier of the batch.\n"},"object":{"type":"string","description":"The object type, which is always \"batch\".\n","enum":["batch"]},"endpoint":{"type":"string","description":"The endpoint used for the batch requests.\n","enum":["/v1/chat/completions","/v1/embeddings","/v1/completions"]},"errors":{"type":"object","description":"Details about any errors encountered during batch processing.\n","nullable":true,"properties":{"object":{"type":"string","enum":["list"]},"data":{"type":"array","items":{"type":"object","properties":{"code":{"type":"string","description":"Error code indicating the type of error.\n"},"message":{"type":"string","description":"Human-readable error message.\n"},"param":{"type":"string","nullable":true,"description":"The parameter that caused the error, if applicable.\n"},"line":{"type":"integer","nullable":true,"description":"The line number in the input file where the error occurred.\n"}}}}}},"input_file_id":{"type":"string","description":"The ID of the input file used for the batch.\n"},"completion_window":{"type":"string","description":"The time frame within which the batch should be processed.\n"},"status":{"type":"string","description":"The current status of the batch.\n","enum":["validating","failed","in_progress","finalizing","completed","expired","cancelling","cancelled"]},"output_file_id":{"type":"string","nullable":true,"description":"The ID of the file containing the outputs of the batch requests. This is only available when the batch status is \"completed\".\n"},"error_file_id":{"type":"string","nullable":true,"description":"The ID of the file containing the errors of the batch requests. This is only available when there are errors in the batch.\n"},"created_at":{"type":"integer","description":"The Unix timestamp (in seconds) for when the batch was created.\n"},"in_progress_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch started processing.\n"},"expires_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch will expire.\n"},"finalizing_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch started finalizing.\n"},"completed_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch was completed.\n"},"failed_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch failed.\n"},"expired_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch expired.\n"},"cancelling_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch cancellation was initiated.\n"},"cancelled_at":{"type":"integer","nullable":true,"description":"The Unix timestamp (in seconds) for when the batch was cancelled.\n"},"request_counts":{"type":"object","description":"Statistics about the requests in the batch.\n","properties":{"total":{"type":"integer","description":"Total number of requests in the batch.\n"},"completed":{"type":"integer","description":"Number of requests that completed successfully.\n"},"failed":{"type":"integer","description":"Number of requests that failed.\n"}},"required":["total","completed","failed"]},"metadata":{"type":"object","nullable":true,"description":"Set of 16 key-value pairs that can be attached to the batch. This can be useful for storing additional information about the batch in a structured format.\n","additionalProperties":{"type":"string"}}},"required":["id","object","endpoint","input_file_id","completion_window","status","created_at","request_counts"]}}},"paths":{"/v1/batches/{batch_id}":{"get":{"tags":["Batches"],"operationId":"get-batch-v1","summary":"Retrieve batch","description":"Look up a single batch by its ID, including its current status and metadata.","parameters":[{"name":"batch_id","in":"path","required":true,"description":"The ID of the batch to retrieve","schema":{"type":"string"}},{"name":"model","in":"query","schema":{"type":"string"},"deprecated":true}],"responses":{"200":{"$ref":"#/components/responses/BatchesResponse"},"400":{"description":"Invalid batch ID format or malformed request"},"404":{"description":"Batch not found"},"500":{"description":"Internal server error"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nexos.ai/gateway-api/batches.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
