# Builder

Uploads, lookups and fixes used by the release builder and the Draft API.

Paths start at `$ACTIVQC_BASE_URL`, and every call sends `Authorization: Bearer $ACTIVQC_KEY`. Errors use the [error envelope](https://activqc.wavbee.com/docs/errors.md). [All endpoints](https://activqc.wavbee.com/docs/api-reference.md).

## POST /v1/builder/cover_fixes

Take what may not be on a cover off it ("Remove it for me")

Queues an AI edit of an uploaded cover that removes what the cover check marked as removable: contact details, promotional text, store names and logos, text that is nowhere on the release, a Parental Advisory mark on a release with no explicit track. Each such finding of `POST /v1/qc/validate` carries `evidence.remediation` (`action: remove_from_cover`) with the `regions` it can remove. Without `regions` the whole cover is fixed in one edit. A title or an artist that does not match is never removed. The edit is checked before it is offered: the rest of the picture must be as it was, and the fixed cover is read again. Ask `GET /v1/builder/cover_fixes/{id}` until `status` is no longer `pending` or `working` (usually 20 to 60 seconds). The cover the release carries is never changed: the answer carries a new upload.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

Send an `Idempotency-Key` header (a new UUID per operation; a retry reuses it).

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `Idempotency-Key` | header | string | **Required.** A unique string per operation, for example a UUID. A retry with the same key returns the first answer. Missing: 422. |

#### Request body

`application/json`.

| Field | Type | Description |
|---|---|---|
| `upload_id` | string | **Required.** The `id` of the cover, from `POST /v1/builder/uploads` |
| `regions` | array of string | The `id`s of the regions to remove (from `evidence.remediation.regions`). Leave out to remove every one. |
| `payload` | object | The draft the cover is judged against, as sent to `POST /v1/qc/validate`. Without it only what a cover alone shows to be removable is (contact details, store and social names and logos, a QR code). |

#### Example request

```bash
curl -s -X POST "$ACTIVQC_BASE_URL/v1/builder/cover_fixes" \
  -H "Authorization: Bearer $ACTIVQC_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "upload_id": "string"
}'
```

#### Responses

| Status | Meaning |
|---|---|
| `202` | Queued, or already answered. |
| `409` | The cover has not been read yet; ask again in a few seconds. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |
| `422` | Not a cover of this tenant's, nothing on it to remove, or a region that is not on it. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `202`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.cover_fix`. |
| `id` | string | **Required.** The id of the cover being fixed |
| `status` | string | **Required.** `ready`: everything asked was removed and the rest of the cover is as it was. `partly_fixed`: something is still on it (`remaining`). `failed`: the edit was thrown away. `unavailable`: no edit could be asked for right now. `refused_by_policy`: the AI would not edit this cover. `capped`: the day's limit is reached. `none`: no fix was asked for. One of `none`, `pending`, `working`, `ready`, `partly_fixed`, `failed`, `unavailable`, `refused_by_policy`, `capped`. |
| `simulated` | boolean | True for a simulated fix (a demo): no image model was called |
| `regions` | array of object | What the fix was asked to remove |
| `regions[].id` | string |  |
| `regions[].rule_id` | string |  |
| `regions[].what` | string |  |
| `regions[].box` | array of number | [x0, y0, x1, y1] on 0..1 |
| `remaining` | array of object | Present when `status` is `partly_fixed`: what is still on the cover |
| `remaining[].id` | string |  |
| `remaining[].what` | string |  |
| `message` | string | One plain sentence for the artist, when the fix is not simply ready |
| `reason` | string | Why, as a code for reviewers (model_not_found, timeout, changed_elsewhere …) |
| `note` | string |  |
| `upload` | object | Present when `status` is `ready` or `partly_fixed`: the fixed cover, to put in the release's artwork if the artist accepts it. It was edited by AI (`ai_edited`). |
| `upload.object` | string |  |
| `upload.id` | string |  |
| `upload.kind` | string |  |
| `upload.filename` | string |  |
| `upload.byte_size` | integer |  |
| `upload.content_type` | string |  |
| `upload.width` | integer |  |
| `upload.height` | integer |  |
| `upload.ai_edited` | boolean |  |
| `upload.url` | string |  |

```json
{
  "object": "builder.cover_fix",
  "id": "string",
  "status": "none",
  "simulated": false,
  "regions": [
    {
      "id": "string",
      "rule_id": "string",
      "what": "string",
      "box": [
        1.0
      ]
    }
  ],
  "remaining": [
    {
      "id": "string",
      "what": "string"
    }
  ],
  "message": "string",
  "reason": "string",
  "note": "string",
  "upload": {
    "object": "string",
    "id": "string",
    "kind": "string",
    "filename": "string",
    "byte_size": 1,
    "content_type": "string",
    "width": 1,
    "height": 1,
    "ai_edited": false,
    "url": "string"
  }
}
```

## GET /v1/builder/cover_fixes/{id}

Where a cover fix has got to.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string | **Required.** The `id` of the cover that is being fixed |

#### Example request

```bash
curl -s "$ACTIVQC_BASE_URL/v1/builder/cover_fixes/{id}" \
  -H "Authorization: Bearer $ACTIVQC_KEY"
```

#### Responses

| Status | Meaning |
|---|---|
| `200` | The fix's state. |
| `404` | No such upload. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `200`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.cover_fix`. |
| `id` | string | **Required.** The id of the cover being fixed |
| `status` | string | **Required.** `ready`: everything asked was removed and the rest of the cover is as it was. `partly_fixed`: something is still on it (`remaining`). `failed`: the edit was thrown away. `unavailable`: no edit could be asked for right now. `refused_by_policy`: the AI would not edit this cover. `capped`: the day's limit is reached. `none`: no fix was asked for. One of `none`, `pending`, `working`, `ready`, `partly_fixed`, `failed`, `unavailable`, `refused_by_policy`, `capped`. |
| `simulated` | boolean | True for a simulated fix (a demo): no image model was called |
| `regions` | array of object | What the fix was asked to remove |
| `regions[].id` | string |  |
| `regions[].rule_id` | string |  |
| `regions[].what` | string |  |
| `regions[].box` | array of number | [x0, y0, x1, y1] on 0..1 |
| `remaining` | array of object | Present when `status` is `partly_fixed`: what is still on the cover |
| `remaining[].id` | string |  |
| `remaining[].what` | string |  |
| `message` | string | One plain sentence for the artist, when the fix is not simply ready |
| `reason` | string | Why, as a code for reviewers (model_not_found, timeout, changed_elsewhere …) |
| `note` | string |  |
| `upload` | object | Present when `status` is `ready` or `partly_fixed`: the fixed cover, to put in the release's artwork if the artist accepts it. It was edited by AI (`ai_edited`). |
| `upload.object` | string |  |
| `upload.id` | string |  |
| `upload.kind` | string |  |
| `upload.filename` | string |  |
| `upload.byte_size` | integer |  |
| `upload.content_type` | string |  |
| `upload.width` | integer |  |
| `upload.height` | integer |  |
| `upload.ai_edited` | boolean |  |
| `upload.url` | string |  |

```json
{
  "object": "builder.cover_fix",
  "id": "string",
  "status": "none",
  "simulated": false,
  "regions": [
    {
      "id": "string",
      "rule_id": "string",
      "what": "string",
      "box": [
        1.0
      ]
    }
  ],
  "remaining": [
    {
      "id": "string",
      "what": "string"
    }
  ],
  "message": "string",
  "reason": "string",
  "note": "string",
  "upload": {
    "object": "string",
    "id": "string",
    "kind": "string",
    "filename": "string",
    "byte_size": 1,
    "content_type": "string",
    "width": 1,
    "height": 1,
    "ai_edited": false,
    "url": "string"
  }
}
```

## POST /v1/builder/fixes

Fix what can be fixed in a builder master ("Fix it for me")

Queues ONE render that makes every fix named in `kinds`, or every safe fix the master calls for when `kinds` is left out: `remove_dc_offset`, `trim_silence`, `lower_peaks`, `save_as_24_bit`, always in that order. The fixes a master calls for are on its findings as `evidence.remediations`, and in `plan` here. A fix another cannot be made without is added (see `plan.steps` in the answer). The result is PCM WAV at the master's own sample rate and channels, 16-bit or 24-bit, dithered (TPDF) when sample values changed. It is measured again and offered only if it is what was set out. Ask `GET /v1/builder/fixes/{id}` until `status` is `done`; the answer then carries the new upload to put in the payload. The original is kept.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

Send an `Idempotency-Key` header (a new UUID per operation; a retry reuses it).

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `Idempotency-Key` | header | string | **Required.** A unique string per operation, for example a UUID. A retry with the same key returns the first answer. Missing: 422. |

#### Request body

`application/json`.

| Field | Type | Description |
|---|---|---|
| `upload_id` | string | **Required.** The `id` of the master, from `POST /v1/builder/uploads` |
| `kinds` | array of string | The fixes to make: one or more of `remove_dc_offset`, `trim_silence`, `lower_peaks`, `save_as_24_bit`. Leave out for every safe fix the master calls for. Any other name is a 422. |

#### Example request

```bash
curl -s -X POST "$ACTIVQC_BASE_URL/v1/builder/fixes" \
  -H "Authorization: Bearer $ACTIVQC_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "upload_id": "string"
}'
```

#### Responses

| Status | Meaning |
|---|---|
| `202` | Queued. |
| `409` | The master has not been measured yet; ask again in a few seconds. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |
| `422` | Not an upload of this tenant's, a fix we do not make, or nothing to fix. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `202`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.audio_fix`. |
| `id` | string | **Required.** The id of the master being fixed |
| `status` | string | **Required.** One of `none`, `running`, `done`, `failed`. |
| `error` | string | Present when `status` is `failed`: the render failed, or the fixed file did not pass our own measurement and was thrown away |
| `plan` | object | What a fix would do now (`status` `none` or `failed`), or what this one does. Absent when there is nothing we can fix. |
| `plan.steps` | array of object | In render order. The same objects a finding carries as `evidence.remediations`. |
| `plan.steps[].action` | string | **Required.** One of `remove_dc_offset`, `trim_silence`, `lower_peaks`, `save_as_24_bit`. |
| `plan.steps[].summary` | string | **Required.** What is done, in plain words with its number |
| `plan.steps[].message` | string | What was measured and why it matters, for the artist |
| `plan.output` | object | The file that comes out: always PCM WAV at the master's own sample rate and channels |
| `plan.output.format` | string |  |
| `plan.output.bit_depth` | integer |  |
| `plan.output.sample_rate_hz` | integer |  |
| `plan.output.channels` | integer |  |
| `plan.output.duration_s` | number |  |
| `plan.output.dither` | string | `triangular` when sample values were changed |
| `verified` | object | Present when `status` is `done`: what our own measurement of the fixed file showed |
| `verified.summary` | string | One sentence for the artist |
| `verified.facts` | array of string |  |
| `verified.true_peak_dbtp` | number |  |
| `verified.integrated_lufs` | number |  |
| `verified.duration_s` | number |  |
| `verified.bit_depth` | integer |  |
| `verified.sample_rate_hz` | integer |  |
| `verified.channels` | integer |  |
| `upload` | object | Present when `status` is `done`: the fixed master, to put in the track's audio |
| `upload.object` | string |  |
| `upload.id` | string |  |
| `upload.kind` | string |  |
| `upload.filename` | string |  |
| `upload.byte_size` | integer |  |
| `upload.content_type` | string |  |
| `upload.duration_s` | number |  |
| `upload.fixed_from` | string | The id of the master it was made from |
| `upload.url` | string |  |

```json
{
  "object": "builder.audio_fix",
  "id": "string",
  "status": "none",
  "error": "string",
  "plan": {
    "steps": [
      {
        "action": "remove_dc_offset",
        "summary": "string",
        "message": "string"
      }
    ],
    "output": {
      "format": "string",
      "bit_depth": 1,
      "sample_rate_hz": 1,
      "channels": 1,
      "duration_s": 1.0,
      "dither": "string"
    }
  },
  "verified": {
    "summary": "string",
    "facts": [
      "string"
    ],
    "true_peak_dbtp": 1.0,
    "integrated_lufs": 1.0,
    "duration_s": 1.0,
    "bit_depth": 1,
    "sample_rate_hz": 1,
    "channels": 1
  },
  "upload": {
    "object": "string",
    "id": "string",
    "kind": "string",
    "filename": "string",
    "byte_size": 1,
    "content_type": "string",
    "duration_s": 1.0,
    "fixed_from": "string",
    "url": "string"
  }
}
```

## GET /v1/builder/fixes/{id}

Where a fix has got to, or what one would do.

`status` is `none` until a fix is started; `plan` then says what one would do now. When `done`, `upload` is the fixed master and `verified` what our measurement of it showed. `failed` means the render failed or did not pass that measurement: there is no file to take.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string | **Required.** The `id` of the master |

#### Example request

```bash
curl -s "$ACTIVQC_BASE_URL/v1/builder/fixes/{id}" \
  -H "Authorization: Bearer $ACTIVQC_KEY"
```

#### Responses

| Status | Meaning |
|---|---|
| `200` | The fix's state. |
| `404` | No such upload. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `200`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.audio_fix`. |
| `id` | string | **Required.** The id of the master being fixed |
| `status` | string | **Required.** One of `none`, `running`, `done`, `failed`. |
| `error` | string | Present when `status` is `failed`: the render failed, or the fixed file did not pass our own measurement and was thrown away |
| `plan` | object | What a fix would do now (`status` `none` or `failed`), or what this one does. Absent when there is nothing we can fix. |
| `plan.steps` | array of object | In render order. The same objects a finding carries as `evidence.remediations`. |
| `plan.steps[].action` | string | **Required.** One of `remove_dc_offset`, `trim_silence`, `lower_peaks`, `save_as_24_bit`. |
| `plan.steps[].summary` | string | **Required.** What is done, in plain words with its number |
| `plan.steps[].message` | string | What was measured and why it matters, for the artist |
| `plan.output` | object | The file that comes out: always PCM WAV at the master's own sample rate and channels |
| `plan.output.format` | string |  |
| `plan.output.bit_depth` | integer |  |
| `plan.output.sample_rate_hz` | integer |  |
| `plan.output.channels` | integer |  |
| `plan.output.duration_s` | number |  |
| `plan.output.dither` | string | `triangular` when sample values were changed |
| `verified` | object | Present when `status` is `done`: what our own measurement of the fixed file showed |
| `verified.summary` | string | One sentence for the artist |
| `verified.facts` | array of string |  |
| `verified.true_peak_dbtp` | number |  |
| `verified.integrated_lufs` | number |  |
| `verified.duration_s` | number |  |
| `verified.bit_depth` | integer |  |
| `verified.sample_rate_hz` | integer |  |
| `verified.channels` | integer |  |
| `upload` | object | Present when `status` is `done`: the fixed master, to put in the track's audio |
| `upload.object` | string |  |
| `upload.id` | string |  |
| `upload.kind` | string |  |
| `upload.filename` | string |  |
| `upload.byte_size` | integer |  |
| `upload.content_type` | string |  |
| `upload.duration_s` | number |  |
| `upload.fixed_from` | string | The id of the master it was made from |
| `upload.url` | string |  |

```json
{
  "object": "builder.audio_fix",
  "id": "string",
  "status": "none",
  "error": "string",
  "plan": {
    "steps": [
      {
        "action": "remove_dc_offset",
        "summary": "string",
        "message": "string"
      }
    ],
    "output": {
      "format": "string",
      "bit_depth": 1,
      "sample_rate_hz": 1,
      "channels": 1,
      "duration_s": 1.0,
      "dither": "string"
    }
  },
  "verified": {
    "summary": "string",
    "facts": [
      "string"
    ],
    "true_peak_dbtp": 1.0,
    "integrated_lufs": 1.0,
    "duration_s": 1.0,
    "bit_depth": 1,
    "sample_rate_hz": 1,
    "channels": 1
  },
  "upload": {
    "object": "string",
    "id": "string",
    "kind": "string",
    "filename": "string",
    "byte_size": 1,
    "content_type": "string",
    "duration_s": 1.0,
    "fixed_from": "string",
    "url": "string"
  }
}
```

## GET /v1/builder/lookups

What the release builder offers to choose from.

What your release builder offers, as your account set it up, by name: languages, genres (`music_styles`), credit roles with their group, track origins and properties, stores with their sections, UGC monetization policies per store, countries (ISO 3166-1 alpha-2) and time zones. A payload carries the names.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Example request

```bash
curl -s "$ACTIVQC_BASE_URL/v1/builder/lookups" \
  -H "Authorization: Bearer $ACTIVQC_KEY"
```

#### Responses

| Status | Meaning |
|---|---|
| `200` | The lists. |
| `401` | Missing or unknown key. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `200`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.lookups`. |
| `languages` | array of object | **Required.** |
| `music_styles` | array of object | **Required.** |
| `contributor_roles` | array of object | **Required.** |
| `track_origins` | array of object | **Required.** |
| `track_property_types` | array of object | **Required.** |
| `stores` | array of object | **Required.** |
| `monetization_policies` | array of object | **Required.** |
| `countries` | array of object | **Required.** |
| `timezones` | array of object | **Required.** |

```json
{
  "object": "builder.lookups",
  "languages": [
    {}
  ],
  "music_styles": [
    {}
  ],
  "contributor_roles": [
    {}
  ],
  "track_origins": [
    {}
  ],
  "track_property_types": [
    {}
  ],
  "stores": [
    {}
  ],
  "monetization_policies": [
    {}
  ],
  "countries": [
    {}
  ],
  "timezones": [
    {}
  ]
}
```

## GET /v1/builder/people

Names the release builder offers while a credit is typed.

Searches the calling tenant's own directory of names to credit, ignoring case and accents. Names that start with `q` come first, then names that hold it anywhere, each alphabetically. An `artist` search (or one with no `kind`) also offers the tenant's artist roster; a name on both is one row. A blank `q` returns the first names alphabetically. A name need not be listed here to be credited.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `q` | query | string | What has been typed so far. |
| `kind` | query | string | Offer only names of this kind: `artist`, `writer`, `producer` or `performer`. Left out: every kind. |
| `limit` | query | integer | How many names at most. 8 when left out, never more than 20. Default `8`. |

#### Example request

```bash
curl -s "$ACTIVQC_BASE_URL/v1/builder/people" \
  -H "Authorization: Bearer $ACTIVQC_KEY"
```

#### Responses

| Status | Meaning |
|---|---|
| `200` | The matching names. |
| `401` | Missing or unknown key. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |
| `422` | A kind the builder does not have. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `200`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.people`. |
| `data` | array of object | **Required.** |
| `data[].name` | string | **Required.** Example `Kavya Rao`. |
| `data[].kinds` | array of string | **Required.** Where the name is offered. A name known only from the artist roster is an `artist`. |
| `data[].legal_name` | string or null | **Required.** A writer’s full name as on their ID, when it differs from `name`. Example `Kavya Raghunath Rao`. |
| `data[].on_roster` | boolean | **Required.** On the tenant’s artist roster. Always false in a writer, producer or performer search. |

```json
{
  "object": "builder.people",
  "data": [
    {
      "name": "Kavya Rao",
      "kinds": [
        "artist"
      ],
      "legal_name": "Kavya Raghunath Rao",
      "on_roster": false
    }
  ]
}
```

## POST /v1/builder/trims

Trim the long silence off a builder master ("Trim it for me")

Queues the trim of an uploaded master whose start or end holds more silence than stores accept. The cut leaves a few seconds of silence and touches nothing else. Ask `GET /v1/builder/trims/{id}` until `status` is `done`; the answer then carries the new upload to put in the payload.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

Send an `Idempotency-Key` header (a new UUID per operation; a retry reuses it).

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `Idempotency-Key` | header | string | **Required.** A unique string per operation, for example a UUID. A retry with the same key returns the first answer. Missing: 422. |

#### Request body

`application/json`.

| Field | Type | Description |
|---|---|---|
| `upload_id` | string | **Required.** The `id` of the master, from `POST /v1/builder/uploads` |

#### Example request

```bash
curl -s -X POST "$ACTIVQC_BASE_URL/v1/builder/trims" \
  -H "Authorization: Bearer $ACTIVQC_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "upload_id": "string"
}'
```

#### Responses

| Status | Meaning |
|---|---|
| `202` | Queued. |
| `409` | The master's silence has not been measured yet; ask again in a few seconds. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |
| `422` | Not an upload of this tenant's, or nothing to trim. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `202`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.trim`. |
| `id` | string | **Required.** The id of the master being trimmed |
| `status` | string | **Required.** One of `none`, `running`, `done`, `failed`. |
| `error` | string | Present when `status` is `failed` |
| `upload` | object | Present when `status` is `done`: the trimmed master, to put in the track's audio |
| `upload.object` | string |  |
| `upload.id` | string |  |
| `upload.kind` | string |  |
| `upload.filename` | string |  |
| `upload.byte_size` | integer |  |
| `upload.content_type` | string |  |
| `upload.duration_s` | number |  |
| `upload.url` | string |  |

```json
{
  "object": "builder.trim",
  "id": "string",
  "status": "none",
  "error": "string",
  "upload": {
    "object": "string",
    "id": "string",
    "kind": "string",
    "filename": "string",
    "byte_size": 1,
    "content_type": "string",
    "duration_s": 1.0,
    "url": "string"
  }
}
```

## GET /v1/builder/trims/{id}

Where a trim has got to.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string | **Required.** The `id` of the master that is being trimmed |

#### Example request

```bash
curl -s "$ACTIVQC_BASE_URL/v1/builder/trims/{id}" \
  -H "Authorization: Bearer $ACTIVQC_KEY"
```

#### Responses

| Status | Meaning |
|---|---|
| `200` | The trim's state. |
| `404` | No such upload. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `200`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.trim`. |
| `id` | string | **Required.** The id of the master being trimmed |
| `status` | string | **Required.** One of `none`, `running`, `done`, `failed`. |
| `error` | string | Present when `status` is `failed` |
| `upload` | object | Present when `status` is `done`: the trimmed master, to put in the track's audio |
| `upload.object` | string |  |
| `upload.id` | string |  |
| `upload.kind` | string |  |
| `upload.filename` | string |  |
| `upload.byte_size` | integer |  |
| `upload.content_type` | string |  |
| `upload.duration_s` | number |  |
| `upload.url` | string |  |

```json
{
  "object": "builder.trim",
  "id": "string",
  "status": "none",
  "error": "string",
  "upload": {
    "object": "string",
    "id": "string",
    "kind": "string",
    "filename": "string",
    "byte_size": 1,
    "content_type": "string",
    "duration_s": 1.0,
    "url": "string"
  }
}
```

## GET /v1/builder/uploads/{id}/waveform

The shape of an uploaded master, for a player's waveform.

About 400 peaks across the master, measured once in the background after the upload. `state` is `pending` until that is done (ask again in a few seconds), then `ready`; `unavailable` means there are none and none are coming, so draw a placeholder. A read: nothing is measured by asking, and no `Idempotency-Key` is needed.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Parameters

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string | **Required.** The `id` of the master, from `POST /v1/builder/uploads` |

#### Example request

```bash
curl -s "$ACTIVQC_BASE_URL/v1/builder/uploads/{id}/waveform" \
  -H "Authorization: Bearer $ACTIVQC_KEY"
```

#### Responses

| Status | Meaning |
|---|---|
| `200` | The waveform, or where it has got to. |
| `404` | No such upload, or not this tenant's. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `200`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.waveform`. |
| `id` | string | **Required.** The id of the uploaded master |
| `state` | string | **Required.** `pending` while the master is still being measured (ask again in a few seconds); `unavailable` when there are no peaks for it and none are coming: draw a placeholder. One of `ready`, `pending`, `unavailable`. |
| `duration_s` | number or null | **Required.** The master's length, once measured |
| `peaks` | array of number | **Required.** About 400 values across the track, each the loudest moment (0.0 to 1.0) of its slice. Empty unless `state` is `ready`. |

```json
{
  "object": "builder.waveform",
  "id": "string",
  "state": "ready",
  "duration_s": 1.0,
  "peaks": [
    1.0
  ]
}
```

## POST /v1/builder/uploads

Upload a builder's cover or master (multipart `file` and `kind`), or finish a direct upload.

`kind` is `artwork` (PNG or JPEG, up to 10 MB), `audio` (WAV or FLAC, up to 500 MB) or `document` (PDF, JPEG or PNG, up to 10 MB: a licence or approval, whose `id` answers an upload question). The answer's `url` is good for an hour; put it in the payload as `{ "url": … }`. The file is removed after two days. Not idempotent: the body is the file itself.

Two ways in. **Multipart**: send `kind` and `file`. A request body over 32 MiB does not reach the hosted engine, so a larger file goes the second way (or is checked from your own link, as `audio.url`). **Direct**: `POST /v1/builder/uploads/direct`, PUT the file to the link it gives, then call this with `kind` and `signed_blob_id` (JSON or form fields) and no `file`. The stored file is then checked: it must be there, be the size and checksum that were described, and its bytes must be an allowed type for the kind. One that is not is removed and refused with a 422. The answer is the same either way.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Request body

`application/json` (or `multipart/form-data`).

| Field | Type | Description |
|---|---|---|
| `kind` | string | `artwork`, `audio` or `document`; anything else is refused with a 422 that says so |
| `file` | string (binary) | The file itself (multipart only) |
| `signed_blob_id` | string | Instead of `file`: the `signed_blob_id` from `POST /v1/builder/uploads/direct`, once the file has been PUT |

#### Example request

```bash
curl -s -X POST "$ACTIVQC_BASE_URL/v1/builder/uploads" \
  -H "Authorization: Bearer $ACTIVQC_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

#### Responses

| Status | Meaning |
|---|---|
| `201` | The upload (here: a direct upload, finished) |
| `404` | No such direct upload: not this key's tenant's, not this kind's, or not from the direct step. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |
| `422` | No kind, no file, or a file that is not allowed (a direct upload's is removed) [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `201`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.upload`. |
| `id` | string | **Required.** The upload's id: what a waveform, a trim or an upload answer is asked for by |
| `kind` | string | **Required.** One of `artwork`, `audio`, `document`. |
| `filename` | string | **Required.** |
| `byte_size` | integer | **Required.** |
| `content_type` | string | **Required.** |
| `url` | string | **Required.** A link to the file, good for an hour: the payload carries it as `{ "url": … }` |

```json
{
  "object": "builder.upload",
  "id": "string",
  "kind": "artwork",
  "filename": "string",
  "byte_size": 1,
  "content_type": "string",
  "url": "string"
}
```

## POST /v1/builder/uploads/direct

Start a direct upload: describe the file, get a link to PUT it to.

For a file too large to send through the API (a request body over 32 MiB does not reach the hosted engine), and what the release builder uses for every master. Nothing is stored by this call. Describe the file; the same kinds, types and size limits apply as to the multipart upload. Then `PUT` the file's bytes to `upload.url` with exactly the headers in `upload.headers` (and no others: the link is signed for them) within `upload.expires_in` seconds, and finish with `POST /v1/builder/uploads` (`kind` and `signed_blob_id`). Until it is finished the file is not an upload: it has no `id` and no link, and nothing reads it. An upload that is never finished is removed after two days. `501` means this engine's storage takes no direct uploads: send multipart.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Request body

`application/json`.

| Field | Type | Description |
|---|---|---|
| `kind` | string | **Required.** `artwork`, `audio` or `document` |
| `filename` | string | The file's name; the kind when left out |
| `byte_size` | integer | **Required.** The file's size in bytes |
| `checksum` | string | **Required.** The file's MD5 digest, base64-encoded (24 characters). Storage refuses bytes that do not match it. |
| `content_type` | string | **Required.** What the file is, e.g. `audio/wav`. Checked again from the stored bytes at the finish. |

#### Example request

```bash
curl -s -X POST "$ACTIVQC_BASE_URL/v1/builder/uploads/direct" \
  -H "Authorization: Bearer $ACTIVQC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "kind": "string",
  "byte_size": 1,
  "checksum": "string",
  "content_type": "string"
}'
```

#### Responses

| Status | Meaning |
|---|---|
| `201` | Where to send the file. |
| `422` | No kind, size or checksum, a type the kind does not take, or a file over its limit. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |
| `501` | This engine's storage takes no direct uploads: send the file as multipart. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `201`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `builder.direct_upload`. |
| `signed_blob_id` | string | **Required.** What the finish step is given. It opens nothing else: it is not an upload's `id`. |
| `kind` | string | **Required.** One of `artwork`, `audio`, `document`. |
| `filename` | string | **Required.** |
| `byte_size` | integer | **Required.** |
| `content_type` | string | **Required.** |
| `upload` | object | **Required.** |
| `upload.method` | string | **Required.** Always `PUT`. |
| `upload.url` | string | **Required.** Where the file's bytes go. Signed: it takes this file only. |
| `upload.headers` | map of string | **Required.** Send exactly these headers with the PUT, and no `Content-Type` of your own unless one is listed |
| `upload.expires_in` | integer | **Required.** Seconds the link is good for; the PUT must start within them |

```json
{
  "object": "builder.direct_upload",
  "signed_blob_id": "string",
  "kind": "artwork",
  "filename": "string",
  "byte_size": 1,
  "content_type": "string",
  "upload": {
    "method": "PUT",
    "url": "string",
    "headers": {},
    "expires_in": 1
  }
}
```

