# Sessions and projects endpoints

A session groups a run of related generations so the app can show them as one
thread. A project is a named folder for sounds and sessions. Sounds are on
[Sounds endpoints](https://mirli.app/docs/api-sounds/index.md); one session's sounds are
`GET /api/sounds?session_id=<SESSION_ID>`.

Some sounds have no session: anything generated before sessions existed,
uploads and recordings, and audio made inside a story (line reads, splits and
exports). The library lists every sound regardless of session.

A generation or a speech job submitted without a `session_id` creates a
session, titled from the first six words of the prompt (for speech, the `name`
or the first line). The resolved id comes back on the job's `request`. A
`session_id` that no longer exists starts a fresh session, and the job still
runs. Every new sound bumps its session's `updated_at`. A session whose job
was cancelled or failed before it produced audio is deleted, and the server
deletes every session with no sounds when it starts.

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

## Session object

The session endpoints return this object:

| Field | Type | Description |
|---|---|---|
| `id` | string | The session's id |
| `title` | string | Display name |
| `created_at` | string | ISO 8601 time it was made |
| `updated_at` | string | ISO 8601 time its newest sound was made, or `created_at` when it has none |
| `sound_count` | integer | Number of sounds in it |
| `project_id` | string or null | The project it is filed in. Its sounds without a project of their own count as filed there too |

## Project object

The project endpoints return this object:

| Field | Type | Description |
|---|---|---|
| `id` | string | The project's id |
| `name` | string | Display name |
| `created_at` | string | ISO 8601 time it was made |
| `sound_count` | integer | Sounds filed in it: their own `project_id`, or their session's when they have none |

## List sessions

`GET /api/sessions`

Returns the sessions with the most recent activity first.

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

This request lists the ten most recent sessions:

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

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

```json
[
  {
    "id": "5c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
    "title": "Glass bottle shattering on tile",
    "created_at": "2026-11-29T10:00:00.000Z",
    "updated_at": "2026-11-29T10:04:00.000Z",
    "sound_count": 2,
    "project_id": null
  }
]
```

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

## Create a session

`POST /api/sessions`

Creates an empty session. Generating creates one too, so this is for a session
that should exist before its first sound. The body is optional.

| Name | Type | Required | Description |
|---|---|---|---|
| `title` | string | No | 1 to 200 characters. Default `New session` |
| `project_id` | string or null | No | The project to file it in |

This request creates a session with the default title:

```bash
curl -X POST -H 'X-Soundbox: 1' "http://127.0.0.1:17494/api/sessions"
```

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

This endpoint returns only the common errors.

## Get a session

`GET /api/sessions/<SESSION_ID>`

Returns one session.

| Name | Type | Required | Description |
|---|---|---|---|
| `<SESSION_ID>` | string | Yes | The session's id |

This request reads one session:

```bash
curl "http://127.0.0.1:17494/api/sessions/<SESSION_ID>"
```

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

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

## Update a session

`PATCH /api/sessions/<SESSION_ID>`

Renames a session or files it in a project. Its sounds follow the session's
project at once, unless they have a project of their own. Renaming does not
change `updated_at`.

| Name | Type | Required | Description |
|---|---|---|---|
| `<SESSION_ID>` | string | Yes | The session's id |
| `title` | string | No | 1 to 200 characters |
| `project_id` | string or null | No | The project to file it in. `null` takes it out; leaving the field out leaves the project unchanged |

This request files a session in a project:

```bash
curl -X PATCH "http://127.0.0.1:17494/api/sessions/<SESSION_ID>" \
  -H 'Content-Type: application/json' \
  -d '{"project_id": "<PROJECT_ID>"}'
```

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

| Status | Cause |
|---|---|
| `404` | No session has this id |
| `422` | The body has neither `title` nor `project_id`. `detail` is `Nothing to update` |

## Delete a session

`DELETE /api/sessions/<SESSION_ID>`

Deletes a session and every sound in it.

> [!WARNING]
> Deleting a session deletes every sound in it, with its audio file. It cannot
> be undone.

| Name | Type | Required | Description |
|---|---|---|---|
| `<SESSION_ID>` | string | Yes | The session's id |

This request deletes one session and its sounds:

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

A successful response is `204 No Content`.

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

## List projects

`GET /api/projects`

Returns every project, newest first. This endpoint takes no parameters.

This request lists the projects:

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

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

```json
[
  {
    "id": "9e8d7c6b-5a4f-4e3d-8c2b-1a0f9e8d7c6b",
    "name": "Lighthouse game",
    "created_at": "2026-11-28T09:00:00.000Z",
    "sound_count": 14
  }
]
```

This endpoint returns only the common errors.

## Create a project

`POST /api/projects`

Creates an empty project.

| Name | Type | Required | Description |
|---|---|---|---|
| `name` | string | Yes | 1 to 200 characters |

This request creates a project:

```bash
curl -X POST "http://127.0.0.1:17494/api/projects" \
  -H 'Content-Type: application/json' \
  -d '{"name": "Lighthouse game"}'
```

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

This endpoint returns only the common errors.

## Delete a project

`DELETE /api/projects/<PROJECT_ID>`

Deletes a project. Its sounds and sessions stay in the library, no longer
filed in any project.

| Name | Type | Required | Description |
|---|---|---|---|
| `<PROJECT_ID>` | string | Yes | The project's id |

This request deletes one project:

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

A successful response is `204 No Content`.

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