# Batches

> Track thousands of prompts across engines and countries in one call, follow progress and credits, and read each answer as soon as it finishes.

A batch queues up to 10,000 tasks in one call. Use it to ask many prompts on many engines and read the items as they finish.

## Create a batch

`POST /v1/batches` takes a list of items. Each item is one task.

```bash
curl -X POST https://promptgale.com/v1/batches \
  -H "Authorization: Bearer $PROMPTGALE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      { "customId": "q1-chatgpt", "taskType": "CHATGPT", "payload": { "prompt": "best crm", "country": "US" } },
      { "customId": "q1-gemini", "taskType": "GEMINI", "payload": { "prompt": "best crm", "country": "US" } }
    ],
    "webhookUrl": "https://example.com/hooks/promptgale",
    "idempotencyKey": "run-2026-11-21"
  }'
```

| Field | Type | Description |
| --- | --- | --- |
| `items` | array | Up to 10,000. Each: `customId?`, `taskType`, `payload`, `idempotencyKey?`, `webhookUrl?`. |
| `webhookUrl` | string | Called once with `batch.completed`, and for each item without its own `webhookUrl`. |
| `idempotencyKey` | string | The same key and body within 30 days returns the first batch (`200`). A different body under the key is `409`. |
| `metadata` | object | Your own data, returned with the batch. |

Every item is checked first. One bad item refuses the whole batch and names the failing indexes.

## How a batch runs

- Items enter the queue as room frees up. Each account keeps at most twice its concurrency limit of batch tasks queued or running.
- Accounts and batches take turns. Your single tasks go before queued batch tasks of the same priority.
- Credits are held per item when it is queued. An item you cannot pay for at that moment ends `rejected` with `INSUFFICIENT_CREDITS`.

## Follow a batch

| Action | Request |
| --- | --- |
| Counts, percent done, credits held and charged | `GET /v1/batches/{id}` |
| Read the items, with results | `GET /v1/batches/{id}/items?include=result` |
| List your batches | `GET /v1/batches?status=OPEN` |
| Stop a batch | `POST /v1/batches/{id}/cancel` |

Cancelling rejects the pending items and cancels the queued tasks, releasing their credits. Tasks that are already running finish.

## When it ends

When every item has finished, `webhookUrl` receives `{"event":"batch.completed","data":<batch>}`. It is signed like a task webhook, over `${batchId}.${timestamp}.${rawBody}`. See [Webhooks](https://promptgale.com/docs/webhooks.md).

---

Docs index: https://promptgale.com/llms.txt · Full reference: https://promptgale.com/llms-full.txt · OpenAPI: https://promptgale.com/v1/openapi.json
