# Prompt assistant endpoints

The prompt assistant is an optional language model. It rewrites a terse prompt
("scary sound") into a descriptive one, writes lyrics, answers questions about
Mirli, and turns studio instructions into edits. These endpoints call it and
manage the engine and models it runs on. Saved assistant conversations are on
[Chat history endpoints](https://mirli.app/docs/api-conversations/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).

## Assistant modes

The `llm_mode` setting decides what answers, and is `off` by default. It is set
with [`PATCH /api/settings`](https://mirli.app/docs/api-settings/index.md), together with `llm_model`,
`llm_external_base_url`, `llm_external_model` and `llm_external_api_key`:

| `llm_mode` | What runs |
|---|---|
| `off` | Nothing. Every endpoint that calls the model answers `400` with a message saying what to set up |
| `managed` | A small model Mirli installs and manages: `llama-server` and a curated GGUF |
| `external` | Any OpenAI-compatible endpoint the settings name, such as one already running on this machine |

An endpoint that calls the model returns `400` with `detail` and a
[failure object](https://mirli.app/docs/api-errors/index.md#failure-object) when the mode is `off`, the
external endpoint has no base URL or model, the managed engine or model is not
installed, or the model does not answer, times out, returns an HTTP error or
returns nothing.

## Rewrite a prompt

`POST /api/enhance`

Rewrites a prompt into descriptive variations, with suggested tags.

| Name | Type | Required | Description |
|---|---|---|---|
| `prompt` | string | Yes | 1 to 2,000 characters |
| `n` | integer | No | 1 to 5 variations. Default 1 |
| `category` | string | No | `sfx` or `music` |
| `lyrics` | boolean | No | Whether the prompt is for a lyrics model |
| `model` | string | No | The model the prompt is for, so the rewrite follows that model's prompting conventions. An unknown or missing id means generic guidance |

This request rewrites "scary sound" for Stable Audio:

```bash
curl -X POST "http://127.0.0.1:17494/api/enhance" \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "scary sound",
    "category": "sfx",
    "model": "audiocpp-stable-audio-3-sfx"
  }'
```

A successful response is `200 OK` with the variations and tags. `tags` are
suggestions for the library's tags, not part of the prompt:

```json
{
  "variations": [
    "heavy wooden door slamming shut in a stone corridor"
  ],
  "tags": ["door", "slam"]
}
```

| Status | Cause |
|---|---|
| `400` | The assistant is off, not set up, or did not answer: see [Assistant modes](#assistant-modes) |

## Write lyrics

`POST /api/enhance/lyrics`

Writes a song's lyrics from a theme.

| Name | Type | Required | Description |
|---|---|---|---|
| `theme` | string | Yes | What the song is about. 1 to 2,000 characters |
| `style` | string | No | The current style prompt, so the lyrics' tags agree with it. Up to 2,000 characters |

This request writes lyrics for a lighthouse song:

```bash
curl -X POST "http://127.0.0.1:17494/api/enhance/lyrics" \
  -H 'Content-Type: application/json' \
  -d '{
    "theme": "a lighthouse keeper alone in a storm",
    "style": "folk, acoustic guitar"
  }'
```

A successful response is `200 OK` with the lyrics as one string:

```json
{
  "lyrics": "[verse]\nThe lamp turns slow across the sea"
}
```

| Status | Cause |
|---|---|
| `400` | The assistant is off, not set up, or did not answer: see [Assistant modes](#assistant-modes) |

## Send an assistant message

`POST /api/assistant/chat`

Runs one turn of the assistant, which answers questions about Mirli from its
documentation and the installed models. The server keeps no conversation
state, so the request carries the whole thread; the model reads the last 20
turns. The assistant runs nothing and proposes no request.

| Name | Type | Required | Description |
|---|---|---|---|
| `messages` | object[] | Yes | 1 to 60 turns of `{ role, content }`. `role` is `user` or `assistant`; `content` is 1 to 8,000 characters |
| `draft` | object | No | The composer's contents: `model` and `prompt`, and optionally `negative_prompt`, `lyrics`, `track_name`, `duration_s` and up to 20 `tags` |
| `studio` | object | No | The open timeline: up to 200 `tracks` (`track_index`, `name`, `muted`, `soloed`), up to 500 `clips` (`id`, `track_index`, `start_s`, `duration_s`, `label`), `playhead_s` and `selected_ids` |

This request asks which model suits a door slam:

```bash
curl -X POST "http://127.0.0.1:17494/api/assistant/chat" \
  -H 'Content-Type: application/json' \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "Which model should I use for a door slam?"
      }
    ],
    "draft": {
      "model": "audiocpp-stable-audio-3-sfx",
      "prompt": "door slam"
    }
  }'
```

A successful response is `200 OK` with the reply. `links` are pages in the app
the reply points at, and `sources` names the documentation sections it drew
on:

```json
{
  "reply": "Stable Audio 3.0 SFX is made for short effects like this.",
  "links": [
    {
      "to": "/models",
      "label": "Models"
    }
  ],
  "sources": ["docs/GENERATING.md › Writing a prompt"]
}
```

| Status | Cause |
|---|---|
| `400` | The assistant is off, not set up, or did not answer: see [Assistant modes](#assistant-modes) |

## List conversation openers

`POST /api/assistant/openers`

Suggests two to four first messages for an empty chat, written for the
installed models and the open timeline. When the model's answer holds fewer
than two, the response is a fixed set of openers.

| Name | Type | Required | Description |
|---|---|---|---|
| `studio` | object | No | The open timeline, in the same shape as on [Send an assistant message](#send-an-assistant-message) |

This request asks for openers with no timeline open:

```bash
curl -X POST "http://127.0.0.1:17494/api/assistant/openers" \
  -H 'Content-Type: application/json' \
  -d '{}'
```

A successful response is `200 OK` with the openers. `label` is the chip's
text and `text` is the message it sends:

```json
{
  "openers": [
    {
      "label": "Horror door",
      "text": "I need a door slam for a horror game"
    },
    {
      "label": "Lo-fi loop",
      "text": "Write me a 20 second lo-fi beat to loop under a menu"
    }
  ]
}
```

| Status | Cause |
|---|---|
| `400` | The assistant is off, not set up, or did not answer: see [Assistant modes](#assistant-modes) |

## Plan a studio command

`POST /api/studio/command`

Turns an instruction into a plan of edits for the open timeline. The server
applies nothing: the caller applies the actions.

| Name | Type | Required | Description |
|---|---|---|---|
| `instruction` | string | Yes | 1 to 2,000 characters |
| `context` | object | Yes | The timeline: `tracks` (up to 200; each `track_index`, `name`, `muted`, `soloed` and up to 32 `devices`, the device kinds in chain order), `clips` (up to 500), `playhead_s`, `selected_ids`, and up to 200 `voices` a written line may be cast to, as `{ id, name, kind, notes }` with `kind` `clone` or `builtin` |

This request takes the reverb off a vocal track:

```bash
curl -X POST "http://127.0.0.1:17494/api/studio/command" \
  -H 'Content-Type: application/json' \
  -d '{
    "instruction": "take the reverb off the vocal",
    "context": {
      "tracks": [
        {
          "track_index": 0,
          "name": "Vocal",
          "devices": ["reverb"]
        }
      ],
      "clips": []
    }
  }'
```

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

```json
{
  "intent": "edit",
  "actions": [
    {
      "type": "remove_device",
      "track_index": 0,
      "kind": "reverb"
    }
  ],
  "summary": "Took the reverb off the Vocal track.",
  "dropped": 0,
  "classified": "edit"
}
```

| Field | Description |
|---|---|
| `intent` | `edit`, or `generate` when the text describes audio to make rather than a change and the plan has no actions |
| `actions` | The edits. `type` is `rename_track`, `set_track`, `move_clip`, `set_clip`, `delete_clip`, `add_clip`, `add_lines`, `speak_lines`, `add_device`, `remove_device`, `set_device`, `generate_clip`, `show_panel` or `start_recording` |
| `summary` | One line about what is about to happen |
| `dropped` | How many actions were removed because they named a clip, track or voice not in `context` |
| `classified` | The planner the instruction was routed to: `edit`, `generate_clip`, `compose`, `script` or `panel` |

| Status | Cause |
|---|---|
| `400` | The assistant is off, not set up, or did not answer: see [Assistant modes](#assistant-modes) |

## Get the assistant status

`GET /api/llm/status`

Returns the mode, the install state of the engine and models, and the local
model servers found on this machine. This endpoint takes no parameters.

This request reads the status:

```bash
curl "http://127.0.0.1:17494/api/llm/status"
```

A successful response is `200 OK` with the status. The example is abridged to
part of one catalogue entry:

```jsonc
{
  "mode": "off",
  "engine": {
    "installed": false,
    "version": null,
    "backend": null
  },
  "model": null,
  "catalog": [
    {
      "id": "qwen3-1.7b",
      "name": "Qwen3 1.7B",
      "vendor": "Alibaba",
      "license": "Apache-2.0",
      "hf_repo": "Qwen/Qwen3-1.7B-GGUF",
      "filename": "Qwen3-1.7B-Q8_0.gguf",
      "size_bytes": 1834426016,
      "recommended": true,
      "installed": false
      // ...more fields
    }
    // ...more catalogue entries
  ],
  "external": {
    "base_url": "",
    "model": "",
    "api_key_set": false
  },
  "running": false,
  "detected": [
    {
      "label": "Ollama",
      "base_url": "http://127.0.0.1:11434",
      "models": ["llama3.1"]
    }
  ]
}
```

| Field | Description |
|---|---|
| `mode` | The `llm_mode` setting |
| `engine` | Whether `llama-server` is installed, and its version and backend |
| `model` | The catalogue entry `llm_model` names, or `null` |
| `catalog` | The assistant models, `qwen3-0.6b`, `qwen3-1.7b` and `qwen3-4b`, each with a `description` and `installed` |
| `external` | The external endpoint's base URL and model, and whether a key is set |
| `running` | Whether the managed `llama-server` is running |
| `detected` | A probe of the default ports of Ollama (11434), LM Studio (1234) and `llama-server` (8080). Each server whose OpenAI-compatible `/v1/models` answers is listed with the model ids it reports |

This endpoint returns only the common errors.

## Install the assistant engine

`POST /api/llm/engine/install`

Queues a job that installs `llama-server`. When an install is already running,
the response is that job.

| Name | Type | Required | Description |
|---|---|---|---|
| `version` | string | No | `latest` or a release tag such as `v1.2.3` |
| `backend` | string | No | Accepted and not used by this endpoint |

This request installs the latest engine:

```bash
curl -X POST -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/llm/engine/install"
```

A successful response is `202 Accepted` with the job's id. Its progress is on
[Get a job](https://mirli.app/docs/api-jobs/index.md#get-a-job):

```json
{
  "job_id": "8d1f2c4a-5b6e-4f70-9a81-2c3d4e5f6a7b"
}
```

| Status | Cause |
|---|---|
| `403` | The server's capabilities turn `downloads` off |

## Download an assistant model

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

Queues a job that downloads one catalogue model's GGUF. When that model is
already downloading, the response is that job.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | `qwen3-0.6b`, `qwen3-1.7b` or `qwen3-4b` |

This request downloads Qwen3 1.7B:

```bash
curl -X POST -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/llm/models/qwen3-1.7b/download"
```

A successful response is `202 Accepted` with the job's id:

```json
{
  "job_id": "2b7e9c1d-3f4a-4e5b-8c6d-7e8f9a0b1c2d"
}
```

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

## Delete an assistant model

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

Deletes one catalogue model's weights from disk. A model that is not
downloaded is not an error.

| Name | Type | Required | Description |
|---|---|---|---|
| `<MODEL_ID>` | string | Yes | `qwen3-0.6b`, `qwen3-1.7b` or `qwen3-4b` |

This request deletes Qwen3 4B:

```bash
curl -X DELETE -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/llm/models/qwen3-4b"
```

A successful response is `204 No Content`.

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