API reference
Batch jobs
Extract a list of URLs as one job. Create, read, list, results, pause, resume and cancel
8 min read
A batch job takes a list of URLs and extracts each one as an item of the same job. It runs on the server, so it keeps running when your program stops. Read its state by polling, read its items' results by page, or download them as a file.
The batch routes are not in the API reference yet. The SDKs have a method for each, from 0.7.0 (Python, TypeScript, Go, Java).
| Route | Does |
|-------|------|
| POST /api/v1/organizations/{org_id}/batch-jobs | Creates a batch and queues it |
| GET /api/v1/organizations/{org_id}/batch-jobs/{batch_job_id} | One batch |
| GET /api/v1/organizations/{org_id}/batch-jobs | The organisation's batches, newest first |
| GET /api/v1/organizations/{org_id}/batch-jobs/{batch_job_id}/results | The items and what each extracted |
| GET /api/v1/organizations/{org_id}/batch-jobs/{batch_job_id}/export | The results as a file (export) |
| POST /api/v1/organizations/{org_id}/batch-jobs/{batch_job_id}/pause | Pauses a running batch |
| POST /api/v1/organizations/{org_id}/batch-jobs/{batch_job_id}/resume | Resumes a paused batch |
| POST /api/v1/organizations/{org_id}/batch-jobs/{batch_job_id}/cancel | Cancels a batch that has not ended |
All of them take the organisation's API key (Authorization: Bearer sk-live-...). Creating a batch needs a live key: a test key answers 403 with detail.error test_key_not_allowed.
Create a batch
curl -X POST https://api.kloakd.dev/api/v1/organizations/$ORG_ID/batch-jobs \
-H "Authorization: Bearer sk-live-..." -H "Content-Type: application/json" \
-d '{
"urls": [
"https://books.toscrape.com/catalogue/page-1.html",
"https://books.toscrape.com/catalogue/page-2.html"
],
"entity_type": "products",
"fields": ["title", "price"]
}'
| Field | Type | Description |
|-------|------|-------------|
| urls | array | Required. The pages to extract, one item each: a URL string, or an object with a url. An empty or missing list answers 422. At most your plan's page limit for a crawl; more answers 413 |
| entity_type | string | Optional. What the items are, such as "products" |
| fields | array of strings | Optional. The field names you want |
| extraction_config | object | Optional. Its selectors key, {field: "css selector"}, is used when neither entity_type nor fields is given |
| crawl_id | string | Optional. The crawl the URLs came from; it is stored with each item |
A key the route does not know is ignored, not refused. A body that is not a JSON object, or a urls that is not a list, answers 422 with the list of validation errors in detail (status codes). The batch's name is set by the server (Batch Extraction (2 URLs)).
It answers 201 with the batch:
{
"id": "…",
"name": "Batch Extraction (2 URLs)",
"status": "pending",
"total_items": 2,
"completed_items": 0,
"created_at": "2026-11-12T10:00:00",
"message": null
}
| Field | Type | Description |
|-------|------|-------------|
| id | string | The batch's id |
| name | string | Set by the server |
| status | string | See states |
| total_items | integer | The number of URLs |
| completed_items | integer | Items worked on to an end, whether they completed or failed. It counts processed items, not successful ones |
| created_at | string | When the batch was created |
| message | string or null | A note on the state: set while the batch is paused or held_quota, otherwise null |
Creating a batch is gated like other work: 429 when the organisation's data allowance is used up, 402 when a paid plan is unpaid (errors). Usage is counted by the bytes each item fetches, not per item. Each item checks the allowance again when it starts.
Read a batch
curl https://api.kloakd.dev/api/v1/organizations/$ORG_ID/batch-jobs/$BATCH_JOB_ID \
-H "Authorization: Bearer sk-live-..."
It answers the same object as create. An unknown id answers 404. Poll it until status is completed, failed or cancelled.
List batches
curl "https://api.kloakd.dev/api/v1/organizations/$ORG_ID/batch-jobs?page=1&page_size=20" \
-H "Authorization: Bearer sk-live-..."
page starts at 1 (the default). page_size is 1 to 100 (default 20). The answer is {"total": …, "batch_jobs": […]}, newest first, each entry the object above.
status lists only the batches in that state: one of pending, running, paused, completed, failed, cancelled or held_quota (states). Repeat it for several states. total and the pages are then over the matching batches. Any other value answers 422.
curl "https://api.kloakd.dev/api/v1/organizations/$ORG_ID/batch-jobs?status=running&status=paused" \
-H "Authorization: Bearer sk-live-..."
Results
curl "https://api.kloakd.dev/api/v1/organizations/$ORG_ID/batch-jobs/$BATCH_JOB_ID/results?limit=100&offset=0" \
-H "Authorization: Bearer sk-live-..."
| Field | Type | Description |
|-------|------|-------------|
| batch_job_id | string | The batch |
| results | array | One entry per item, in the order the items were created: job_id, url, status, extracted_data and api_data |
| total_jobs | integer | Items counted |
| completed_jobs | integer | Items that completed |
| failed_jobs | integer | Items that failed |
limit is 1 to 1000 and offset is 0 or more. Send limit: with it, the three counts are of the whole batch. Without it the route returns every item it read and the counts are of those items only.
States
| Status | Meaning |
|--------|---------|
| pending | Created, not started yet |
| running | Items are being worked on |
| paused | Paused by you. Items that were already running finish; the rest wait |
| held_quota | The organisation's allowance ran out. The batch is held, not failed, and resumes by itself when the allowance is raised |
| completed | Every item has ended. Items may have failed: read the results |
| failed | The batch could not be run |
| cancelled | Cancelled by you |
completed, failed and cancelled are final.
| Action | Allowed from | Result | Repeating it | Otherwise |
|--------|--------------|--------|--------------|-----------|
| pause | running | paused | A paused batch answers 200, unchanged | 409 |
| resume | paused | running | A running batch answers 200, unchanged | 409 |
| cancel | pending, running, paused, held_quota | cancelled | A cancelled batch answers 200, unchanged | 409 for completed or failed |
Each action answers 200 with the batch object.
- Pause. Items already running finish; no other item starts. A
pendingbatch cannot be paused: wait until it isrunning, or cancel it. A paused batch whose running items were its last ones becomescompleted. - Resume. The waiting items are queued again, once each. Resume is gated like create: the data allowance, the plan's payment and the limit on batches at once all apply. A batch that is
held_quotacannot be resumed by this route; it resumes by itself. - Cancel. The batch and its items that are pending, running or held become
cancelled. Items that had completed or failed keep their results.
Errors
Error bodies carry the code in detail.error, as on the other routes (errors).
A control the batch's state does not allow answers 409:
{
"detail": {
"error": "invalid_batch_transition",
"message": "Only a running batch can be paused (current status: completed).",
"action": "pause",
"status": "completed"
}
}
action is pause, resume or cancel; status is the batch's status at the time.
An organisation runs a limited number of batches at once, set by the plan. Create and resume answer 409 when the limit is reached:
{
"detail": {
"error": "concurrent_limit",
"message": "Concurrent batch limit reached (10 for free tier). Wait for a running batch to finish.",
"tier": "free",
"concurrent_limit": 10,
"active_batches": 10
}
}
active_batches counts the organisation's batches that are pending or running. The limit is the plan's number of jobs that run at once (fair use). Note that the count is named active_batches here and active_crawls on the crawl's limit.
A batch that could not be handed to the workers answers 503:
{
"detail": {
"error": "dispatch_failed",
"message": "The batch could not be queued and was not started. Try again.",
"batch_job_id": "…"
}
}
On create, the batch named by batch_job_id is stored as failed; create a new one. On resume, the body also has items_not_queued and the batch is paused again; resume it again.
| Status | detail.error | When |
|--------|----------------|------|
| 403 | test_key_not_allowed | Create with a test key |
| 404 | | Unknown batch id (detail is a sentence, not an object) |
| 409 | invalid_batch_transition | Pause, resume or cancel from a state that does not allow it |
| 409 | concurrent_limit | Create or resume while the plan's number of batches at once is in use |
| 413 | batch_too_large | More URLs than the plan's page limit. The body has tier, max_items and requested_items |
| 422 | | Create: urls empty or missing (detail is the sentence urls must be a non-empty list), or a body that is not an object or a urls that is not a list (detail is the list of validation errors). List: a status that is not a batch state |
| 503 | dispatch_failed | The batch, or a resumed batch's items, could not be queued |
Next steps
- Batch extraction guide: the other ways to extract many pages, and the export formats
- Unified scrape: one page, with the level chosen for you
- Error reference
