Guides

Batch

What it is for

When you have many requests and do not need the answers straight away, send them as one batch. Antarya works through them in the background, and you collect the replies when the batch is done. Batch requests are billed at their own price.

Create a batch

Each request in the batch has a custom_id you choose and the same body you would send to /v1/chat.

curl https://antarya.ai/v1/batches \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {
        "custom_id": "contract-001",
        "params": {"messages": [{"role": "user", "content": "Summarise this contract'"'"'s termination clause."}]}
      },
      {
        "custom_id": "contract-002",
        "params": {"messages": [{"role": "user", "content": "Draft a reply that declines the meeting."}]}
      }
    ]
  }'
Output
{
  "id": "batch_01",
  "status": "in_progress",
  "request_counts": {"total": 2, "done": 0}
}

Collect the results

GET /v1/batches/{id} returns the status. When it is ended, GET /v1/batches/{id}/results returns one line of JSON per request, each with its custom_id and either a reply or an error. See whether there is an error before you read reply. The lines may come in any order, so match them on custom_id.

curl https://antarya.ai/v1/batches/batch_01 \
  -H "Authorization: Bearer $ANTARYA_API_KEY"

curl https://antarya.ai/v1/batches/batch_01/results \
  -H "Authorization: Bearer $ANTARYA_API_KEY"

To stop a batch, call POST /v1/batches/{id}/cancel. Requests already finished keep their replies.

Parameters

NameTypeRequiredDescription
requestsarrayYesRequiredThe requests to run.
custom_idtextYesRequiredYour own label for the request. Each one in a batch must be different.
paramsobjectYesRequiredThe body of a chat request, with the same fields as POST /v1/chat except `stream` and `session_id`, which a batch request cannot use.

Limits

A batch holds up to 1,000 requests and its results arrive within 24 hours. A request still unrun after 24 hours comes back as a result line with an error of type overloaded and the message "This request did not run within 24 hours." There is no expired status. Results are kept for 30 days after the batch ends. An account can have 5 batches in progress and 10,000 queued requests. Calls to the batch endpoints count against the management limit in rate limits; the requests inside a batch do not count against the chat limits. cancel stops the requests that have not run and the batch ends.

Limit Value
Requests in one batch 1,000 requests
Time to finish Within 24 hours
Batches in progress 5 an account
Queued requests 10,000 an account
Batch price To be announced

Next steps