# Chat history endpoints

A conversation is a saved thread of what happened in a studio: what was said,
the edits that were applied, and the sounds that came of it. The studio's
**History** panel uses these endpoints, so a reopened timeline shows how it got
that way. The assistant itself keeps no state; see
[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).

## Conversation object

The conversation endpoints return this object:

| Field | Type | Description |
|---|---|---|
| `id` | string | The conversation's id |
| `title` | string | Display name. `New conversation` until named; the first user entry with text names an unnamed, empty conversation, cut to about 48 characters |
| `story_id` | string or null | The story it belongs to. A story has at most one conversation. Becomes `null` when the story is deleted |
| `created_at` | string | ISO 8601 time it was made |
| `updated_at` | string | ISO 8601 time of the last append or rename |
| `entry_count` | integer | Number of entries |

## Entry object

An entry is one turn of cause and effect. Every field but `role` can be empty,
since a question has words and no effect, and a render has an effect and no
words:

| Field | Type | Description |
|---|---|---|
| `id` | string | The entry's id |
| `conversation_id` | string | The conversation it is in |
| `position` | integer | Its place in the conversation, from 0 |
| `role` | string | `user` for something a person typed or clicked, `assistant` for a reply or an action taken for them |
| `content` | string | What was said. Empty when nothing was |
| `actions` | string[] | One line per edit applied, in the words the chat showed |
| `sound_ids` | string[] | Sounds this turn produced |
| `job_id` | string or null | The job that carried it out |
| `created_at` | string | ISO 8601 time it was appended |

## List conversations

`GET /api/conversations`

Returns the most recently updated conversations, newest first. With
`?story_id`, it returns that story's conversation instead, as a list of zero or
one.

| Name | Type | Required | Description |
|---|---|---|---|
| `?limit` | integer | No | 1 to 200. Default 50. Ignored with `?story_id` |
| `?story_id` | string | No | One story's conversation |

This request reads one story's conversation:

```bash
curl "http://127.0.0.1:17494/api/conversations?story_id=<STORY_ID>"
```

A successful response is `200 OK` with a list of
[conversation objects](#conversation-object):

```json
[
  {
    "id": "6a2f8e1c-9d3b-4c7a-8e5f-1b2c3d4e5f60",
    "title": "Add a door slam at four seconds",
    "story_id": "0c9b8a7d-6e5f-4a3b-9c2d-1e0f9a8b7c6d",
    "created_at": "2026-11-29T10:00:00.000Z",
    "updated_at": "2026-11-29T10:04:00.000Z",
    "entry_count": 2
  }
]
```

| Status | Cause |
|---|---|
| `422` | `limit` is not an integer from 1 to 200 |

## Create a conversation

`POST /api/conversations`

Creates a conversation. When `story_id` names a story that already has one,
the response is that existing conversation.

| Name | Type | Required | Description |
|---|---|---|---|
| `title` | string | No | 1 to 200 characters. Default `New conversation` |
| `story_id` | string | No | The story it belongs to |

This request creates a conversation for one story:

```bash
curl -X POST "http://127.0.0.1:17494/api/conversations" \
  -H 'Content-Type: application/json' \
  -d '{"story_id": "<STORY_ID>"}'
```

A successful response is `201 Created` with the
[conversation object](#conversation-object).

This endpoint returns only the common errors.

## Get a conversation

`GET /api/conversations/<CONVERSATION_ID>`

Returns one conversation, without its entries.

| Name | Type | Required | Description |
|---|---|---|---|
| `<CONVERSATION_ID>` | string | Yes | The conversation's id |

This request reads one conversation:

```bash
curl "http://127.0.0.1:17494/api/conversations/<CONVERSATION_ID>"
```

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

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

## Rename a conversation

`PATCH /api/conversations/<CONVERSATION_ID>`

Changes a conversation's title and bumps its `updated_at`.

| Name | Type | Required | Description |
|---|---|---|---|
| `<CONVERSATION_ID>` | string | Yes | The conversation's id |
| `title` | string | Yes | 1 to 200 characters. Surrounding spaces are trimmed |

This request renames a conversation:

```bash
curl -X PATCH \
  "http://127.0.0.1:17494/api/conversations/<CONVERSATION_ID>" \
  -H 'Content-Type: application/json' \
  -d '{"title": "Gate scene"}'
```

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

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

## Delete a conversation

`DELETE /api/conversations/<CONVERSATION_ID>`

Deletes a conversation and all its entries. The sounds its entries name are
kept.

| Name | Type | Required | Description |
|---|---|---|---|
| `<CONVERSATION_ID>` | string | Yes | The conversation's id |

This request deletes one conversation:

```bash
curl -X DELETE -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/conversations/<CONVERSATION_ID>"
```

A successful response is `204 No Content`.

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

## List entries

`GET /api/conversations/<CONVERSATION_ID>/entries`

Returns every entry in a conversation, in order.

| Name | Type | Required | Description |
|---|---|---|---|
| `<CONVERSATION_ID>` | string | Yes | The conversation's id |

This request reads a conversation's entries:

```bash
curl \
  "http://127.0.0.1:17494/api/conversations/<CONVERSATION_ID>/entries"
```

A successful response is `200 OK` with a list of
[entry objects](#entry-object):

```json
[
  {
    "id": "f1e2d3c4-b5a6-4978-8a9b-0c1d2e3f4a5b",
    "conversation_id": "6a2f8e1c-9d3b-4c7a-8e5f-1b2c3d4e5f60",
    "position": 0,
    "role": "assistant",
    "content": "Added a door slam at 0:04.",
    "actions": ["Added clip on lane 2"],
    "sound_ids": ["3f6c1b9e-2a4d-4f0e-9c1a-7b5d2e8f0a11"],
    "job_id": null,
    "created_at": "2026-11-29T10:04:00.000Z"
  }
]
```

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

## Append entries

`POST /api/conversations/<CONVERSATION_ID>/entries`

Adds entries to the end of a conversation in one write and bumps its
`updated_at`. The server assigns each entry's `id`, `position` and
`created_at`.

| Name | Type | Required | Description |
|---|---|---|---|
| `<CONVERSATION_ID>` | string | Yes | The conversation's id |
| `entries` | object[] | Yes | 1 to 50 entries |
| `entries[].role` | string | Yes | `user` or `assistant` |
| `entries[].content` | string | No | Up to 8,000 characters |
| `entries[].actions` | string[] | No | Up to 100 lines of up to 400 characters |
| `entries[].sound_ids` | string[] | No | Up to 50 sound ids |
| `entries[].job_id` | string or null | No | The job that carried it out |

This request appends a question and its answer:

```bash
curl -X POST \
  "http://127.0.0.1:17494/api/conversations/<CONVERSATION_ID>/entries" \
  -H 'Content-Type: application/json' \
  -d '{
    "entries": [
      {
        "role": "user",
        "content": "Add a door slam at four seconds"
      },
      {
        "role": "assistant",
        "content": "Added a door slam at 0:04.",
        "actions": ["Added clip on lane 2"]
      }
    ]
  }'
```

A successful response is `201 Created` with every entry in the conversation,
in order, as a list of [entry objects](#entry-object).

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