# Work Queues API

Source: https://docs.autessa.com/docs/api/workqueues

> Enqueue and track large batches of work: durable, grouped, staged units of work processed at scale with retries and dedup.

# Work Queues API

A work queue is a durable backlog of individual units of work — each an invocation of one of your tools with a payload — that the platform processes reliably, with retries, per-item timeouts, grouping, and staged ordering. Use it to fan a large job out into many independent items and track them to completion.

> All Work Queues API requests require an `Authorization` header with your API key. These endpoints are company-scoped by the key, so — unlike the AutessaDB API — they take no `resourceId` query parameter. Every item that names a tool to run is checked against your key's permissions for that tool before it is accepted.

---

## Base URL

```
https://api.autessa.com/clients/workqueues
```

---

## Authentication

Pass your API key in the `Authorization` header (no "Bearer" prefix):

```
Authorization: your_api_key_here
```

```bash title="cURL"
curl https://api.autessa.com/clients/workqueues/progress \
  -H "Authorization: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{ "queueId": "b1a7...", "groupKey": "batch-2026-07" }'
```

---

## Concepts

A **queue** is a named, long-lived backlog. Queues are created and configured in the [Builder](https://builder.autessa.com) — where you set their concurrency, default attempt and timeout limits, and stage precedence — and you reference an existing queue by its `queueId` when enqueuing.

An **item** is one unit of work: a tool to invoke (`actionToolId`) and the `payload` of per-invocation values it runs with. Each item moves through states — `PENDING`, `RUNNING`, and then a terminal `SUCCEEDED`, `FAILED`, `DEAD` (failed past its `maxAttempts`), or `CANCELLED`.

A **group** collects related items under a shared `groupKey` so you can track and act on a batch as a whole. Group counters are maintained as items complete, so [progress](#progress-) is a fast read regardless of how many items the group holds.

A **stage** is an optional label on an item. When a queue defines an ordered **stage precedence**, items in earlier-listed stages are leased for processing ahead of later stages — and any staged item is leased ahead of unstaged ones. This drives depth-first completion: a multi-stage pipeline finishes the items already in flight through their later stages before pulling new work in at the first stage. A stage is just a name to the API; the ordering comes from the queue's configured precedence list.

---

## Enqueue Items **POST** `/enqueue`

Adds one or more items to a queue in a single call. Every item that sets `actionToolId` is authorized against your API key's permission for that tool before anything is written — if any item fails the check, the whole batch is rejected and nothing is enqueued.

### Request Body

- `queueId` (string, required) — ID of the queue to add items to.
- `items` — " required> The items to enqueue. Each has the fields below.

**EnqueueItem**

- `actionToolId` (string, required) — ID of the tool this item invokes when it runs. Your API key must have permission for this tool.
- `payload` (object) — Per-invocation values for the tool's `@@{...}` placeholders — the same kind of input you would pass when running the tool directly.
- `groupKey` (string) — Groups this item with others under a shared key for batch tracking and group actions.
- `stage` (string) — Optional stage label. Its effect on ordering comes from the queue's configured stage precedence.
- `priority` (integer) — Explicit lease priority (lower is leased first). When set, it overrides any stage precedence for this item.
- `maxAttempts` (integer) — How many times the item may run before it is marked `DEAD`. Defaults to the queue's configured maximum.
- `timeoutSeconds` (integer) — Per-run timeout for this item. Defaults to the queue's configured timeout.
- `delaySeconds` (integer) — Hold the item invisible for this many seconds before it becomes eligible to run.
- `dedupKey` (string) — Optional idempotency key. An item whose `dedupKey` matches a still-live (pending or running) item already on the same queue is skipped rather than enqueued — so a retried or re-delivered enqueue never creates a duplicate. Items with no `dedupKey` are never deduplicated.

### Response

- `enqueued` (integer) — Number of items actually added.
- `itemIds` — "> IDs of the enqueued items, in request order.
- `skipped` (integer) — Number of items silently skipped as `dedupKey` duplicates (0 when none).
- `errors` — "> Error messages if the batch was rejected.

```bash title="cURL"
curl --request POST \
  --url 'https://api.autessa.com/clients/workqueues/enqueue' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: your_api_key' \
  --data '{
    "queueId": "b1a7c0de-2f3a-4c5b-9d1e-7a8b9c0d1e2f",
    "items": [
      {
        "actionToolId": "V1StGXR8Z5",
        "groupKey": "batch-2026-07",
        "stage": "extract",
        "payload": { "s3Uri": "temp/files/1024/doc-001.pdf" },
        "dedupKey": "doc-001"
      },
      {
        "actionToolId": "V1StGXR8Z5",
        "groupKey": "batch-2026-07",
        "stage": "extract",
        "payload": { "s3Uri": "temp/files/1024/doc-002.pdf" },
        "dedupKey": "doc-002"
      }
    ]
  }'
```

```json title="JSON"
{
  "enqueued": 2,
  "itemIds": [
    "9f1c2b3a-4d5e-6f70-8192-a3b4c5d6e7f8",
    "0a1b2c3d-4e5f-6071-8293-b4c5d6e7f809"
  ],
  "skipped": 0,
  "errors": []
}
```

---

## Progress **POST** `/progress`

Returns the live counters for one group: how many of its items are in each state, per-stage totals and completions, and an overall status. This is a fast read — it consults the maintained group counters, not a scan of every item.

### Request Body

- `queueId` (string, required) — ID of the queue the group belongs to.
- `groupKey` (string, required) — The group to report on.

### Response

- `group` (WorkGroup) — The group's counters, or `null` if no items have ever been enqueued under this `(queueId, groupKey)`.
- `errors` — "> Error messages if any occurred.

**WorkGroup**

- `nTotal` (integer) — Total items enqueued in the group.
- `nPending` (integer) — Items waiting to run.
- `nRunning` (integer) — Items currently running.
- `nSucceeded` (integer) — Items that completed successfully.
- `nFailed` (integer) — Items whose latest attempt failed (and may retry).
- `nDead` (integer) — Items that exhausted their attempts.
- `nCancelled` (integer) — Items that were cancelled.
- `stageCounts` (object) — Per-stage progress: a map of stage name to `{ "total": ..., "done": ... }`.
- `status` (string) — The group's overall status.

```bash title="cURL"
curl --request POST \
  --url 'https://api.autessa.com/clients/workqueues/progress' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: your_api_key' \
  --data '{
    "queueId": "b1a7c0de-2f3a-4c5b-9d1e-7a8b9c0d1e2f",
    "groupKey": "batch-2026-07"
  }'
```

```json title="JSON"
{
  "group": {
    "queueId": "b1a7c0de-2f3a-4c5b-9d1e-7a8b9c0d1e2f",
    "groupKey": "batch-2026-07",
    "nTotal": 500,
    "nPending": 120,
    "nRunning": 8,
    "nSucceeded": 360,
    "nFailed": 4,
    "nDead": 2,
    "nCancelled": 6,
    "stageCounts": {
      "extract": { "total": 500, "done": 498 },
      "classify": { "total": 498, "done": 372 }
    },
    "status": "ACTIVE"
  },
  "errors": []
}
```

---

## List Items **POST** `/items/list`

Lists items on a queue, filtered by state, stage, and/or group, with pagination. Use it to inspect individual items — their payloads, results, attempt counts, and last error.

### Request Body

- `queueId` (string, required) — ID of the queue to list from.
- `state` (string) — Filter to one state: `PENDING`, `RUNNING`, `SUCCEEDED`, `FAILED`, `DEAD`, or `CANCELLED`.
- `stage` (string) — Filter to one stage.
- `groupKey` (string) — Filter to one group.
- `page` (integer) — Zero-based page number. Defaults to 0.
- `size` (integer) — Items per page. Defaults to 50.

### Response

- `items` — "> The matching items. Each carries `id`, `queueId`, `groupKey`, `stage`, `state`, `priority`, `attempt`, `maxAttempts`, `actionToolId`, `payload`, `result`, `lastError`, `timeoutSeconds`, `visibleAt`, `createdAt`, and `completedAt`.
- `totalElements` (integer) — Total items matching the filter.
- `totalPages` (integer) — Total pages at the requested size.
- `page` (integer) — The page returned.
- `errors` — "> Error messages if any occurred.

```bash title="cURL"
curl --request POST \
  --url 'https://api.autessa.com/clients/workqueues/items/list' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: your_api_key' \
  --data '{
    "queueId": "b1a7c0de-2f3a-4c5b-9d1e-7a8b9c0d1e2f",
    "groupKey": "batch-2026-07",
    "state": "DEAD",
    "page": 0,
    "size": 50
  }'
```

```json title="JSON"
{
  "items": [
    {
      "id": "0a1b2c3d-4e5f-6071-8293-b4c5d6e7f809",
      "queueId": "b1a7c0de-2f3a-4c5b-9d1e-7a8b9c0d1e2f",
      "groupKey": "batch-2026-07",
      "stage": "extract",
      "state": "DEAD",
      "priority": 10,
      "attempt": 3,
      "maxAttempts": 3,
      "actionToolId": "V1StGXR8Z5",
      "payload": { "s3Uri": "temp/files/1024/doc-002.pdf" },
      "result": {},
      "lastError": "Extraction timed out",
      "timeoutSeconds": 300,
      "visibleAt": "2026-07-15T14:30:00Z",
      "createdAt": "2026-07-15T14:00:00Z",
      "completedAt": "2026-07-15T14:35:10Z"
    }
  ],
  "totalElements": 2,
  "totalPages": 1,
  "page": 0,
  "errors": []
}
```

---

## Retry Dead Items **POST** `/retry-dead`

Requeues every `DEAD` item in a group — resetting its attempt count and making it eligible to run again. Use it after fixing whatever caused a batch of items to exhaust their retries.

### Request Body

- `queueId` (string, required) — ID of the queue.
- `groupKey` (string, required) — The group whose dead items to requeue.

### Response

- `count` (integer) — Number of items moved back to `PENDING`.
- `errors` — "> Error messages if any occurred.

```bash title="cURL"
curl --request POST \
  --url 'https://api.autessa.com/clients/workqueues/retry-dead' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: your_api_key' \
  --data '{
    "queueId": "b1a7c0de-2f3a-4c5b-9d1e-7a8b9c0d1e2f",
    "groupKey": "batch-2026-07"
  }'
```

```json title="JSON"
{
  "count": 2,
  "errors": []
}
```

---

## Cancel Group **POST** `/cancel-group`

Cancels a group's outstanding work: items that are `PENDING` or `FAILED` move to `CANCELLED`. Items already `RUNNING` are left to finish, and items that have already reached a terminal state are unaffected.

### Request Body

- `queueId` (string, required) — ID of the queue.
- `groupKey` (string, required) — The group to cancel.

### Response

- `count` (integer) — Number of items moved to `CANCELLED`.
- `errors` — "> Error messages if any occurred.

```bash title="cURL"
curl --request POST \
  --url 'https://api.autessa.com/clients/workqueues/cancel-group' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: your_api_key' \
  --data '{
    "queueId": "b1a7c0de-2f3a-4c5b-9d1e-7a8b9c0d1e2f",
    "groupKey": "batch-2026-07"
  }'
```

```json title="JSON"
{
  "count": 118,
  "errors": []
}
```

---

## Related

- [Tools API](/docs/api/tools.md) — the tools an item invokes when it runs
- [Document tool types](/docs/tools/documents.md) — bulk-intake and per-document processing designed to run as queue items
- [AutessaDB API](/docs/api/autessadb.md) — multipart upload for the large archives a bulk-intake queue processes

