Skip to content

Create batch

POST https://api.fastapi.ai/v1/batches

Creates and executes a batch from an uploaded file of requests.

Request body


completion_window string Required
The time frame within which the batch should be processed. Currently only 24h is supported.


endpoint string Required
The endpoint to be used for all requests in the batch.

Currently /v1/responses, /v1/chat/completions, /v1/embeddings, /v1/completions, and /v1/moderations are supported.

Note: /v1/embeddings batches are restricted to a maximum of 50,000 embedding inputs across all requests in the batch.


input_file_id string Required
The ID of an uploaded file that contains requests for the new batch.

Your input file must be formatted as a JSONL 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.


metadata map Optional
Set of 16 key-value pairs that can be attached to an object. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.


output_expires_after object

The expiration policy for the output and/or error file that are generated for a batch.


anchor string Required
Anchor timestamp after which the expiration policy applies. Supported anchors: created_at.


seconds integer Required
The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).

Returns


Returns the Batch object.

The created Batch object.

Example

Request

bash
curl https://api.fastapi.ai/v1/batches \
  -H "Authorization: Bearer $FAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input_file_id": "file-abc123",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h"
  }'

Response

bash
{
  "id": "batch_abc123",
  "object": "batch",
  "endpoint": "/v1/chat/completions",
  "errors": null,
  "input_file_id": "file-abc123",
  "completion_window": "24h",
  "status": "validating",
  "output_file_id": null,
  "error_file_id": null,
  "created_at": 1711471533,
  "in_progress_at": null,
  "expires_at": null,
  "finalizing_at": null,
  "completed_at": null,
  "failed_at": null,
  "expired_at": null,
  "cancelling_at": null,
  "cancelled_at": null,
  "request_counts": {
    "total": 0,
    "completed": 0,
    "failed": 0
  },
  "metadata": {
    "customer_id": "user_123456789",
    "batch_description": "Nightly eval job"
  }
}

那年我双手插兜, 让bug稳如老狗