# Models endpoints

A model is an engine the server renders with: weights on this machine run by
audio.cpp, or a [custom endpoint](https://mirli.app/docs/endpoints/index.md) reached over HTTP. The
audio.cpp runtime is on [audio.cpp runtime endpoints](https://mirli.app/docs/api-audiocpp/index.md), image
models on [Artwork endpoints](https://mirli.app/docs/api-artwork/index.md), and language models on
[Prompt assistant endpoints](https://mirli.app/docs/api-assistant/index.md).

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).

## Model object

The model endpoints return this object:

| Field | Type | Description |
|---|---|---|
| `id`, `name`, `vendor`, `description` | string | What the model is |
| `license` | object | `name`, `commercial` (`yes`, `no` or `conditional`), `url` and `note` |
| `hf_repo` | string | The Hugging Face repository of its weights. Empty for weights on disk |
| `gated` | boolean | The repository is gated on Hugging Face |
| `family` | string | audio.cpp's loader family, such as `stable_audio` |
| `task` | string | The job it runs: `gen`, `tts`, `vc`, `sep` or `asr` |
| `category` | string | `sfx`, `music`, `voice` or `utility` |
| `params` | object[] | The knobs the family accepts: the keys `request_options` takes. Empty means the words and the voice are the only controls |
| `voice_ids` | string[] | Built-in voice names. Empty when only a reference clip picks a voice |
| `requires_voice_reference` | boolean | No default voice; reads only with a cloned one |
| `max_duration_s` | number | Longest render in seconds |
| `sample_rate`, `channels` | integer | Output format |
| `supports` | object | What the model takes; see [the supports flags](#supports-flags) |
| `defaults` | object | Default `duration_s`, `steps` and `cfg` |
| `max_cfg` | number or null | Highest `cfg` accepted |
| `vram_estimate_mb` | integer | Expected VRAM use. `0` for an endpoint |
| `provider` | string | `local` (weights on this machine, run by audio.cpp) or `endpoint` (a custom endpoint) |
| `metered` | boolean | A render may cost money. Never picked by default, by the app or by MCP |
| `downloadable` | boolean | Has weights to fetch, load and delete |
| `status` | string | Whether it can be used now; see [the status values](#status-values) |
| `installed_deps` | boolean | Whether the runtime half is installed, on its own |
| `auto_installable`, `manual_install_reason`, `install_command` | boolean, string or null | Whether the runtime installs itself, and what to do when not |
| `extras` | string[] | `["audio-cpp"]` for a local model |
| `error`, `failure` | string, object | Why `status` is `error`; `failure` is a [failure object](https://mirli.app/docs/api-errors/index.md#failure-object) |
| `download_failure` | object or null | Why the last download failed: a failure object plus `at` (ISO 8601). Kept across restarts until a download succeeds, the weights are deleted, or it is dismissed. Set only while `status` is `not_installed` or `incomplete` |
| `active_job_id` | string or null | The download's job, while `status` is `downloading` |
| `avg_duration_s` | number or null | Rolling average wall time in seconds of recent successful generate jobs, `null` until one completes. The app shows it before **Generate** is clicked; it feeds `eta_s` on this model's queued jobs |

### Status values

`status` covers both the weights and the runtime:

| `status` | Meaning |
|---|---|
| `not_installed` | No weights on disk |
| `needs_runtime` | Weights downloaded, audio.cpp runtime missing. **Install runtime** on the Models page, `soundbox model install audiocpp` or [installing the runtime](https://mirli.app/docs/api-audiocpp/index.md#install-the-audiocpp-runtime) fixes it; there is nothing to download again |
| `incomplete` | Part of the weights is on disk, not enough to run. Downloading again fetches the rest |
| `downloading` | A download job is running |
| `installed` | Ready to load |
| `loaded` | In memory |
| `error` | See `error` |

### Supports flags

`supports` holds booleans: `negative_prompt`, `seed`, `steps`, `cfg`, `lyrics`,
`text` (reads a script), `voice_reference` (clones from a clip), the edits
`extend`, `cover` and `repaint`, and `streaming` (reads a line as it is
generated, on this audio.cpp build).

## List models

`GET /api/models`

Returns every model the server offers, with its status and licence. When the
server's capabilities turn `local_models` off, models with `provider: "local"`
are left out. This endpoint takes no parameters.

This request lists the models:

```bash
curl "http://127.0.0.1:17494/api/models"
```

A successful response is `200 OK` with an array of
[model objects](#model-object). The example is abridged:

```jsonc
[
  {
    "id": "audiocpp-stable-audio-3-sfx",
    "name": "Stable Audio 3.0 SFX (audio.cpp)",
    "vendor": "Stability AI",
    "license": {
      "name": "Stability AI Community License",
      "commercial": "conditional",
      "url": "https://stability.ai/license"
    },
    "hf_repo": "audio-cpp/audio.cpp-gguf",
    "family": "stable_audio",
    "task": "gen",
    "category": "sfx",
    "max_duration_s": 120,
    "sample_rate": 44100,
    "channels": 2,
    "defaults": {
      "duration_s": 10,
      "steps": 8,
      "cfg": 1
    },
    "max_cfg": 3,
    "vram_estimate_mb": 2500,
    "provider": "local",
    "status": "installed",
    "installed_deps": true,
    "error": null,
    "avg_duration_s": 187.4
    // ...more fields
  }
]
```

This endpoint returns only the common errors.

## Get a model

`GET /api/models/<MODEL_ID>`

Returns one model.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | The model's id |

This request reads one model:

```bash
curl "http://127.0.0.1:17494/api/models/audiocpp-ace-step"
```

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

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

## Download a model

`POST /api/models/<MODEL_ID>/download`

Queues a job that downloads the model's weights from Hugging Face, continuing
an interrupted download. For an audio.cpp model with no runtime found, the job
installs the runtime first, in phase `installing`. While one is running, the endpoint returns that job
instead of queuing another. Success clears `download_failure` and lists the
model in every profile.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | The model's id |

This request downloads one model:

```bash
curl -X POST -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/models/audiocpp-ace-step/download"
```

A successful response is `202 Accepted` with the job's id. Progress streams
from [the job's events](https://mirli.app/docs/api-jobs/index.md#stream-a-jobs-events):

```json
{
  "job_id": "8d1f4c2a-6b3e-4f7a-9e2d-5c0b1a7f3e64"
}
```

| Status | Cause |
|---|---|
| `400` | No model has this id. The body has `detail` and `failure` |
| `403` | The server's capabilities turn `downloads` off |

## Dismiss a download failure

`DELETE /api/models/<MODEL_ID>/download-failure`

Forgets the remembered failure of the model's last download, so
`download_failure` becomes `null`.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | The model's id |

This request dismisses one model's download failure:

```bash
curl -X DELETE -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/models/audiocpp-ace-step/download-failure"
```

A successful response is `204 No Content`.

| Status | Cause |
|---|---|
| `403` | The server's capabilities turn `downloads` off |
| `404` | No model has this id |

## Test a model

`POST /api/models/<MODEL_ID>/selftest`

Renders about one second through the job queue, loading the model if needed,
and saves nothing. Only `gen` and `tts` models can be tested; any other task,
or a model that reads only with a cloned voice, answers `ok: false`.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | The model's id |

This request tests one model:

```bash
curl -X POST -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/models/audiocpp-stable-audio-3-sfx/selftest"
```

A successful response is `200 OK` with the result: `device` as the health
endpoint names it, wall time including any load, and seconds of audio
rendered:

```json
{
  "model": "audiocpp-stable-audio-3-sfx",
  "ok": true,
  "device": "cuda",
  "elapsed_s": 4.2,
  "rendered_s": 1.0,
  "error": null
}
```

A failed render is also `200 OK`, with `ok: false`, `rendered_s: null` and
`error` set.

| Status | Cause |
|---|---|
| `400` | No model has this id. The body has `detail` and `failure` |
| `403` | The server's capabilities turn `local_models` off |

## Load a model

`POST /api/models/<MODEL_ID>/load`

Loads the model into memory. One model is resident at a time, so any other
loaded model is unloaded first. A model that is already loaded is returned as
it is.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | The model's id |

This request loads one model:

```bash
curl -X POST -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/models/audiocpp-stable-audio-3-sfx/load"
```

A successful response is `200 OK` with the [model object](#model-object), its
`status` now `loaded`.

| Status | Cause |
|---|---|
| `400` | No model has this id, the runtime is missing, or the load failed. The body has `detail` and `failure` |
| `403` | The server's capabilities turn `local_models` off |

## Unload a model

`POST /api/models/<MODEL_ID>/unload`

Releases the model from memory. A model that is not loaded is returned
unchanged.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | The model's id |

This request unloads one model:

```bash
curl -X POST -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/models/audiocpp-stable-audio-3-sfx/unload"
```

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

| Status | Cause |
|---|---|
| `400` | No model has this id. The body has `detail` and `failure` |
| `403` | The server's capabilities turn `local_models` off |

## Delete a model's weights

`DELETE /api/models/<MODEL_ID>/weights`

Deletes the model's downloaded weights, unloading it first if it is loaded, and
clears `download_failure`. Files another catalogue entry shares stay on disk. A
model listed only because its weights were on disk drops out of the list; one
enabled in settings stays.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | The model's id |

This request deletes one model's weights:

```bash
curl -X DELETE -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/models/audiocpp-ace-step/weights"
```

A successful response is `204 No Content`.

| Status | Cause |
|---|---|
| `400` | No model has this id, no weights were found, or it has none to delete: a custom endpoint, or a `custom.json` entry with `weights_path`, whose files Mirli did not download (see [Add your own model](https://mirli.app/docs/audiocpp-models/index.md)). The body has `detail` and `failure` |
| `403` | The server's capabilities turn `downloads` off |
