# Jobs endpoints

A job is one piece of slow work the server runs in its queue: a generation,
a download, a stem split, a speech read, an export. The endpoints that start
one answer `202 Accepted` with a `job_id`, and these endpoints list, read,
cancel and stream jobs. Jobs are held in memory: the server keeps the 200 most
recent and forgets them on restart. At most 10 generation jobs (`generate`,
`speak`, `convert`, `separate` and `transcribe`) wait at once.

Each endpoint lists the errors it returns itself. Any endpoint can also return
the [common errors](https://mirli.app/docs/api-errors/index.md#common-errors).

## Job object

The job endpoints return this object:

| Field | Type | Description |
|---|---|---|
| `id` | string | The job's id |
| `kind` | string | `generate`, `download`, `separate`, `speak`, `convert`, `segment`, `export`, `selftest` or `transcribe` |
| `status` | string | `queued`, `running`, `done`, `error` or `cancelled`. The last three are terminal |
| `phase` | string | `queued`, `installing`, `loading`, `downloading`, `generating`, `encoding` or `done` |
| `progress` | number | 0 to 1 |
| `message` | string | What the job is doing now, such as `Generating` or `Variation 2/3` |
| `error` | string or null | The error message when `status` is `error` |
| `failure` | object or null | Set with `error`: a [failure object](https://mirli.app/docs/api-errors/index.md#failure-object) |
| `request` | object | The request body as the server stored it. A generation's `session_id` is the resolved session |
| `result` | object or null | `null` until done. A `generate` or `separate` job gives `{ "sounds": [...] }`, the new sound ids; a generation with `separate` also gives `sources`, the mixes the stems came from |
| `created_at` | string | ISO 8601 time it was queued |
| `started_at`, `finished_at` | string or null | ISO 8601 times it started and reached a terminal status |
| `queue_position` | integer or null | 1-based position among the queued jobs, oldest first. `null` once running or finished |
| `eta_s` | number or null | Rough seconds until the job starts: the running job's remaining time plus the jobs ahead, from the average of recent successful jobs of the same kind and model. `null` with no timing history, or when the job is not queued |

This is a queued generation. The example is abridged:

```jsonc
{
  "id": "5f0c2a9e-3b1d-4c6a-9e2f-8a7b6c5d4e3f",
  "kind": "generate",
  "status": "queued",
  "phase": "queued",
  "progress": 0,
  "message": "",
  "error": null,
  "failure": null,
  "request": {
    "model": "audiocpp-stable-audio-3-sfx",
    "prompt": "heavy wooden door slam, dry room",
    "session_id": "9b2e7d41-6c3a-4f58-8e1d-2a7c5b9f0e64"
    // ...more fields
  },
  "result": null,
  "created_at": "2026-11-29T10:00:00.000Z",
  "started_at": null,
  "finished_at": null,
  "queue_position": 2,
  "eta_s": 41.5
}
```

## List jobs

`GET /api/jobs`

Returns recent jobs, newest first.

| Name | Type | Required | Description |
|---|---|---|---|
| `?limit` | integer | No | 1 to 200. Default 50 |

This request lists the ten most recent jobs:

```bash
curl "http://127.0.0.1:17494/api/jobs?limit=10"
```

A successful response is `200 OK` with an array of
[job objects](#job-object).

| Status | Cause |
|---|---|
| `422` | `limit` is not an integer, or is out of range |

## Get a job

`GET /api/jobs/<JOB_ID>`

Returns one job. A finished job's `result.sounds` are library sounds,
and their audio is at `/files/<SOUND_ID>.wav` on
[Sounds endpoints](https://mirli.app/docs/api-sounds/index.md#get-a-sounds-audio).

| Name | Type | Required | Description |
|---|---|---|---|
| `<JOB_ID>` | string | Yes | The job's id |

This request reads one job:

```bash
curl "http://127.0.0.1:17494/api/jobs/<JOB_ID>"
```

A successful response is `200 OK` with the [job object](#job-object).

| Status | Cause |
|---|---|
| `404` | No job has this id |

## Cancel a job

`POST /api/jobs/<JOB_ID>/cancel`

Cancels a queued or running job. A queued job is `cancelled` at once. A
running job stops at its next check and then reaches `cancelled`, so the
returned job can still show `running`. A job that has already finished is
returned unchanged.

| Name | Type | Required | Description |
|---|---|---|---|
| `<JOB_ID>` | string | Yes | The job's id |

This request cancels one job:

```bash
curl -X POST -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/jobs/<JOB_ID>/cancel"
```

A successful response is `200 OK` with the [job object](#job-object).

| Status | Cause |
|---|---|
| `404` | No job has this id |

## Stream a job's events

`GET /api/jobs/<JOB_ID>/events`

Streams the job as server-sent events. The first event is the job as it is
now, then one follows on every change, each a `data:` line holding the
[job object](#job-object). The stream closes after the event with a terminal
status, and sends a `: keepalive` comment every 15 seconds while nothing
changes. `GET /api/jobs/<JOB_ID>` gives the same object to a client that does
not read event streams.

| Name | Type | Required | Description |
|---|---|---|---|
| `<JOB_ID>` | string | Yes | The job's id |

This request follows one job until it ends:

```bash
curl -N -H 'Accept: text/event-stream' \
  "http://127.0.0.1:17494/api/jobs/<JOB_ID>/events"
```

A successful response is `200 OK` with `Content-Type: text/event-stream`, one
event per change:

```text
data: <JOB_JSON>

data: <JOB_JSON>
```

`<JOB_JSON>` is the job object on one line.

| Status | Cause |
|---|---|
| `404` | No job has this id |
