# audio.cpp runtime endpoints

audio.cpp is the native runtime that runs every local model. These endpoints
read the catalogue of models it can run, report which `audiocpp_cli` binary
is in force, and install one. The models themselves are on
[Models endpoints](https://mirli.app/docs/api-models/index.md), and [About audio.cpp](https://mirli.app/docs/audiocpp/index.md)
describes the runtime.

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

## List the catalogue

`GET /api/models/audiocpp/catalog`

Returns every model the audio.cpp adapter knows, enabled or not. This endpoint
takes no parameters.

`always_on` models are in [`GET /api/models`](https://mirli.app/docs/api-models/index.md#list-models)
regardless. The rest appear there once their id is in the
`enabled_audiocpp_models` setting
([Update settings](https://mirli.app/docs/api-settings/index.md#update-settings)), which takes effect
without a restart, or once their weights are on disk. Weights are shared by
every profile, so weights on disk enable a model in every profile.

`source` is `builtin` or `custom`. A `custom` entry comes from
`<DATA_DIR>/models/custom.json`, where `<DATA_DIR>` is the data folder.
These entries are always on, never `verified`, and replace a built-in entry
with the same id. That file adds a model Mirli does not ship, including one
whose weights are already on disk; see
[Add your own model](https://mirli.app/docs/audiocpp-models/index.md).

This request lists the catalogue:

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

A successful response is `200 OK` with an array of entries. The example is
abridged:

```jsonc
[
  {
    "source": "builtin",
    "id": "audiocpp-htdemucs-sep",
    "name": "HTDemucs stem separation (audio.cpp)",
    "vendor": "Meta AI (Demucs)",
    "verified": false,
    "always_on": false,
    "enabled": true,
    "on_disk": false,
    "category": "utility"
    // ...more fields
  }
]
```

Each entry has these fields:

| Field | Type | Description |
|---|---|---|
| `id`, `name`, `vendor`, `description` | string | What the model is |
| `license` | object | `name`, `commercial` (`yes`, `no` or `conditional`), `url` and `note` |
| `verified` | boolean | The model has been run and checked with Mirli |
| `always_on` | boolean | Listed in `GET /api/models` whatever the settings |
| `enabled` | boolean | Listed in `GET /api/models`: always on, in `enabled_audiocpp_models`, or on disk |
| `on_disk` | boolean | Its weights are on this machine |
| `category` | string | `sfx`, `music`, `voice` or `utility` |
| `source` | string | `builtin`, or `custom` for an entry from `custom.json` |

This endpoint returns only the common errors.

## Get the runtime status

`GET /api/models/audiocpp/runtime`

Returns which `audiocpp_cli` binary resolved, how it was found, and where
model weights live. The binary is looked for in this order: the
`MIRLI_AUDIOCPP_BIN` environment variable, a managed install, then `PATH`. This
endpoint takes no parameters.

This request reads the runtime status:

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

A successful response is `200 OK` with the status:

```json
{
  "mode": "managed",
  "engine": {
    "installed": true,
    "version": "v0.9.2",
    "path": "/home/me/.mirli/bin/audiocpp/v0.9.2/audiocpp_cli",
    "backend": "cuda",
    "source": "managed"
  },
  "models_dir": "/home/me/.mirli/models/audiocpp",
  "models_dir_default": "/home/me/.mirli/models/audiocpp",
  "install_job_id": null,
  "env_override": null
}
```

| Field | Type | Description |
|---|---|---|
| `mode` | string | The `audiocpp_mode` setting: `managed` (Mirli's own install) or `external` (an audio.cpp already on the machine, sharing its weights) |
| `engine.installed` | boolean | A usable binary was found |
| `engine.version` | string or null | The release tag of a managed install. `null` for a binary found another way |
| `engine.path` | string or null | The binary's path |
| `engine.backend` | string or null | The backend detected on this machine: `metal` on macOS, `cuda` when an NVIDIA driver answers, otherwise `cpu` |
| `engine.source` | string or null | `managed`, `env` (from `MIRLI_AUDIOCPP_BIN`) or `path` |
| `models_dir` | string | The weights folder in force |
| `models_dir_default` | string | The folder a managed install uses, so an override can be told apart |
| `install_job_id` | string or null | The job installing the runtime right now, or `null` |
| `env_override` | string or null | The value of `MIRLI_AUDIOCPP_BIN`, or `null` when it is not set |

This endpoint returns only the common errors.

## Install the audio.cpp runtime

`POST /api/models/audiocpp/engine/install`

Queues a job that downloads an `audiocpp_cli` release from GitHub, checks it
against the release's checksums, and installs it under
`<DATA_DIR>/bin/audiocpp/<VERSION>/`, shared by every profile. The newest
install is the one used. With an empty body, an install already running,
including one a model download started, is returned instead of queuing
another. The body is optional.

| Name | Type | Required | Description |
|---|---|---|---|
| `version` | string | No | `latest` or a release tag, such as `v0.9.2`: letters, digits, dot, dash and underscore, no path segments. Default `latest` |
| `backend` | string | No | A short name, such as `cuda`, `vulkan` or `cpu`, that picks the release asset. Default: the backend detected on this machine |

This request installs the latest release with the Vulkan backend:

```bash
curl -X POST "http://127.0.0.1:17494/api/models/audiocpp/engine/install" \
  -H 'Content-Type: application/json' \
  -d '{"backend": "vulkan"}'
```

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), and a failed
install, such as a release with no asset for this machine, fails the job:

```json
{
  "job_id": "2c7e9b14-5f3a-4d8e-b1c6-9a0f4e7d2b53"
}
```

| Status | Cause |
|---|---|
| `403` | The server's capabilities turn `downloads` off |
| `409` | `MIRLI_AUDIOCPP_BIN` is set, so an installed runtime would never be used. Unset it first |
