# Jobs and Results

A **job** is one PDF. Create it, upload the file straight to storage, submit it, poll its status and read the result. To be told when a job finishes instead of polling, register a [webhook](/webhooks). All routes are Preview (see [Versioning and Preview](/versioning-and-preview)) and use the `Authorization: Bearer <key>` header.

| Step | Call |
|---|---|
| 1. Create | `POST /v1-preview/jobs` with `{"mode": "single"}` or `{"mode": "pack"}`; optional `fileName`, and `scenario` on mock accounts only. Returns `201` and an `upload` block. |
| 2. Upload | `PUT` the PDF to `upload.url` with the headers in `upload.headers` (it goes to UK South storage, never through the gateway). The URL expires at `upload.expiresAt` (15 minutes) and the file may be at most `upload.maxBytes` (200 MiB by default). |
| 3. Submit | `POST /v1-preview/jobs/{jobId}/submit`. Returns `202` when accepted, or `200` with the current state if it already was. |
| 4. Poll | `GET /v1-preview/jobs/{jobId}` until the status is terminal. |
| 5. Read | `GET /v1-preview/jobs/{jobId}/result`. Returns `409` until the job has finished. |
| Clean up | `DELETE /v1-preview/jobs/{jobId}` returns `204`. |

`GET /v1-preview/jobs` lists your jobs, newest first.

## Modes and page caps

- `single`: one certificate in the PDF, at most 50 pages.
- `pack`: one PDF holding certificates from several suppliers, at most 400 pages. It is split first; each certificate is extracted separately.

Submit checks the file size, that it is a readable PDF and the page cap. An unusable file ends the job as `failed` (the response is `413` or `422`): create a new job, because an upload is single use. Submit also returns `402` when the account has used its monthly credit cap (see [Billing](/billing)).

## Statuses

A job moves through `created`, `submitted`, `classifying`, `split` (packs), `extracting`, and ends in one of:

| Terminal status | Meaning |
|---|---|
| `completed` | Every certificate was extracted. |
| `completedWithErrors` | At least one certificate failed; the others are still returned. |
| `infected` | The malware scan flagged the upload. |
| `failed` | The job could not be processed (see `failureReason`). |

Each certificate in a job has its own status: `pending`, `processing`, `completed` or `failed`.

## The result

The result is the same envelope for `single` and `pack` jobs. It has the `jobId`, `mode`, job `status`, `failureReason` (when the job failed), `pageCount`, `scannedPageCount`, `usage` (`scanPages` and `extractPages`), `warnings` and a `certificates` list. Each certificate carries its `supplier`, `classificationConfidence`, `lowConfidence` flag, `sourcePages` (`start`, `end`), `status`, the full extraction `result` document, `tags` and, for a failed certificate, an `error`. Responses are sent with `Cache-Control: no-store` because they may contain extracted certificate content.

## Idempotency

Send an `Idempotency-Key` header (1 to 128 printable characters, no spaces) when you create a job. A retry with the same key returns the original job (`200` instead of `201`) and is never counted against your limits. Reusing a key with a different `mode` or `scenario`, or after the job was deleted, is a `409`. Submit and delete are also safe to repeat.

## Listing and usage

`GET /v1-preview/jobs` accepts `status`, `from`, `to` (ISO 8601, UTC; `from` defaults to 90 days ago), `limit` (1 to 100, default 25) and `cursor` (the `nextCursor` of the previous page). The `totals` cover every job that matches the filter, not just the page: job count and the scan and extraction pages used, for reconciling with an invoice. Mock accounts are never invoiced.

PDFs regrouped per certificate, supplier or heat are available from `GET /v1-preview/jobs/{jobId}/pdf` once the job has finished: see [PDF exports](/pdf-exports).

## Deleting and retention

`DELETE` removes the uploaded PDF, the split certificates and the stored results and hides the job. The usage already recorded is kept for billing. Deleting a running job discards its eventual result.

Without a delete, data is removed automatically: uploaded source PDFs after **7 days** and result documents after **90 days**. Cleanup runs about once a day and can lag by up to two days, and storage soft delete can keep a removed file for a further short period before it is gone for good. Treat 7 and 90 days as the longest you can rely on the data, not as exact deletion times. After a result has been removed its certificate reports "The result is no longer available." Fetch and store results you need within that window. For now these two windows apply to every account's stored files. The `retentionDays` value on `GET /v1-preview/account` is informational and does not change them; per-account retention is planned.

## Limits

Per-account limits (jobs per hour, day and month, jobs in progress, jobs waiting for a file) and the per-key request limits are on [Rate limits and size limits](/rate-limits).
