# Jobs

> Every operation runs as a job: statuses, waiting for the result, webhooks, idempotent retries, listing and canceling.

## Statuses

| Status | Meaning |
|---|---|
| `queued` | Accepted, waiting for a worker. |
| `running` | Being processed; `progress` goes from 0 to 1, `stage` names the step. |
| `succeeded` | Done: `result` and `outputs` are filled in. |
| `failed` | Not done: `error` has a `code`, a `message` and a `docs_url`. Nothing is charged. |
| `canceled` | Canceled by you. Nothing is charged. |

A job that fails because of a passing problem (a worker restarting) is retried by itself: it goes back to `queued`.

## Waiting for the result

Pick one:

- **Wait in the request.** `GET /v1/jobs/{id}?wait=60` answers as soon as the job finishes, or after at most 60 seconds. Ask again while it is `queued` or `running`. This suits scripts and AI agents best.
- **Poll.** `GET /v1/jobs/{id}` answers at once. Ask every 5 to 10 seconds.
- **Webhook.** Add `"webhook": {"url": "https://...", "secret": "..."}` to the request and VAPI calls you when the job finishes. See below.

## Webhooks

When the job finishes, VAPI sends a `POST` to your URL with `{"type": "job.succeeded" | "job.failed" | "job.canceled", "created_at": ..., "data": <the job>}`.

- With a `secret` (16 characters or more), every call is signed: `VAPI-Signature: t=<unix time>,v1=<hex HMAC-SHA256 of "<t>.<body>">`. Check it and the time.
- `VAPI-Event-Id` stays the same across retries: use it to ignore repeats.
- Answer `2xx`. Otherwise VAPI tries again after 30 s, 2 min, 10 min, 30 min and 2 h, then gives up.
- The job shows `webhook.status` (`pending`, `delivered` or `failed`) and the last error, never the secret.
- The URL must reach the internet: private, loopback and link-local addresses are refused.

## Idempotent retries

Send `Idempotency-Key: <a unique string>` with every request that starts a job. If the answer is lost, send the same request with the same key: you get the original job (`Idempotent-Replayed: true`), not a second one. The same key with a different body is refused with `409 idempotency_key_reused`. Keys are each person's own.

## Listing jobs

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

| Parameter | |
|---|---|
| `status` | `queued`, `running`, `succeeded`, `failed` or `canceled`. |
| `operation` | `reframe` or `probe`. |
| `api_key` | Only jobs started with this key (`key_...`). |
| `test` | `true`: only jobs of test keys; `false`: only real ones. |
| `scope` | `mine` (the default) or `organization`: everyone's (owners and admins of the organization). |
| `limit` | 1 to 100, default 20. |
| `starting_after` | A job id: the page after it. `has_more` says whether there is one. |

## Whose jobs

A job is the person's who started it: whoever is signed in to the VAPI panel, or the creator of the API key. `created_by` says who, and with which key. Members see their own jobs; owners and admins of the organization can see everyone's. The organization pays for all of them.

## Canceling

`POST /v1/jobs/{id}/cancel` cancels a queued job at once; a running one stops at its next step. A finished job cannot be canceled (`409 job_not_cancelable`).

## Inputs

A job takes one of:

- `"input": {"url": "https://..."}`: VAPI downloads the video. The address must reach the internet (not a private network) and answer within a minute; files up to 2 GB.
- `"input": {"upload_id": "upl_..."}`: a file you uploaded (`POST /v1/uploads`, then `PUT` to its `upload_url`).
- `"revision_of": "job_..."`: the input of an earlier job (see [Reframe](reframe.md#revisions)).

A URL becomes an upload too: `input.upload_id` in the job, so a revision or another job can reuse it without downloading it again.

## Outputs and how long they are kept

Finished jobs list their files in `outputs`, each with a `url` valid for an hour; `GET` the job again for fresh ones. Output files are kept for 30 days, uploads for 7.
