{
  "openapi": "3.1.0",
  "info": {
    "title": "Montage API",
    "version": "1.0.0",
    "summary": "Render a video from an audio track and a background clip, then publish it to YouTube.",
    "description": "Montage combines an audio track with a background (a YouTube segment, an uploaded clip, or a still image), renders a 1080p video asynchronously, and publishes it to a connected YouTube channel.\n\nAuthenticate with a Bearer API key minted at https://www.usemontage.com/account/api-keys. A key acts as the user who created it.\n\nTypical flow: GET /api/me (preflight) -> POST /api/upload/audio/presign -> PUT the bytes to the presigned URL (no Authorization header) -> POST /api/montage/schedule -> poll GET /api/jobs/{jobId} until complete -> POST /api/publish/intent -> poll GET /api/publish/intent until published.\n\nPOST /api/montage/schedule is NOT idempotent and spends credits: persist the returned jobId before retrying anything. POST /api/publish/intent is safe to retry: it keeps one intent per montage and kind, and returns 409 instead of uploading again once that intent is publishing or published.\n\nAny standard HTTP client works — no User-Agent gating exists on any /api/* route.",
    "contact": {
      "url": "https://www.usemontage.com/docs/agents"
    }
  },
  "servers": [
    {
      "url": "https://www.usemontage.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Account",
      "description": "Identity, credits, and connected channels"
    },
    {
      "name": "Upload",
      "description": "Getting audio into storage"
    },
    {
      "name": "Tracks",
      "description": "The v2 Tracks library (producer audio + properties)"
    },
    {
      "name": "Jobs",
      "description": "Rendering videos"
    },
    {
      "name": "Library",
      "description": "Finished videos"
    },
    {
      "name": "Publishing",
      "description": "YouTube uploads"
    },
    {
      "name": "Packs",
      "description": "The v2 Packs API: Tracks for one Artist, with a private link (owner/agent)"
    },
    {
      "name": "Pack Links",
      "description": "The public pack link a recipient opens — no API key; listening never needs sign-in"
    },
    {
      "name": "Artist Home",
      "description": "The signed-in Artist's inbox, activity feed and owned shelf — cookie session only, no API key"
    },
    {
      "name": "Analytics",
      "description": "All-time pack analytics and live YouTube numbers (owner/agent)"
    },
    {
      "name": "Producer Profile",
      "description": "A producer's page for the Artists they've sent a Pack to — cookie session only, 404 without a claim (requirements §26)"
    }
  ],
  "paths": {
    "/api/me": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getMe",
        "summary": "Preflight: identity, subscription, credits, channels, limits",
        "description": "Call this before starting any workflow. Proceed only when subscription.status is active or trialing, credits.balance >= credits.costPerVideo, and (when publishing) youtubeChannels is non-empty.",
        "responses": {
          "200": {
            "description": "Account snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/youtube/accounts": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "listChannels",
        "summary": "List connected YouTube channels",
        "responses": {
          "200": {
            "description": "Connected channels",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "channels": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Channel"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/credits": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getCredits",
        "summary": "Credit balance and recent ledger",
        "responses": {
          "200": {
            "description": "Balance and ledger",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "integer"
                    },
                    "recentLedger": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "delta": {
                            "type": "integer"
                          },
                          "reason": {
                            "type": "string"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "balance_after": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/upload/audio/presign": {
      "post": {
        "tags": [
          "Upload"
        ],
        "operationId": "presignAudioUpload",
        "summary": "Get a presigned URL for an audio upload",
        "description": "Returns a URL valid for one hour. PUT the raw bytes to it with Content-Type set to the same filetype and NO Authorization header, then pass fileKey to POST /api/montage/schedule as audioStoragePath.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "filename",
                  "filetype",
                  "filesize"
                ],
                "properties": {
                  "filename": {
                    "type": "string",
                    "description": "Extension must be one of .mp3 .wav .flac .aac .ogg .m4a .opus",
                    "example": "beat.mp3"
                  },
                  "filetype": {
                    "type": "string",
                    "description": "MIME type matching the extension",
                    "example": "audio/mpeg"
                  },
                  "filesize": {
                    "type": "integer",
                    "description": "Bytes, at most 209715200 (200 MB)",
                    "maximum": 209715200,
                    "example": 5242880
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upload target",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "presignedUrl": {
                      "type": "string",
                      "format": "uri"
                    },
                    "fileKey": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/upload/video": {
      "post": {
        "tags": [
          "Upload"
        ],
        "operationId": "uploadVideo",
        "summary": "Upload a video clip as a Visual source",
        "description": "Uploads a visual source for `POST /api/montage/schedule` (`video_source_type` `upload`). `multipart/form-data` with the file in `file` (or a raw `video/*` body). Max 500 MB; .mp4, .mov, .webm and similar; content is checked. Rate limited per user.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "tempPath": {
                      "type": "string",
                      "description": "Pass as `uploaded_video_path`"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid file",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/upload/image": {
      "post": {
        "tags": [
          "Upload"
        ],
        "operationId": "uploadImage",
        "summary": "Upload an image as a Visual source",
        "description": "Uploads a visual source for `POST /api/montage/schedule` (`video_source_type` `image`). `multipart/form-data` with the file in `file`. Max 20 MB; .jpg .jpeg .png .webp .gif; content is checked. Rate limited per user.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "tempPath": {
                      "type": "string",
                      "description": "Pass as `uploaded_image_path`"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid file",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/montage/schedule": {
      "post": {
        "tags": [
          "Jobs"
        ],
        "operationId": "scheduleRender",
        "summary": "Create a render job",
        "description": "Spends credits and returns immediately with a jobId. NOT idempotent — persist the jobId before retrying anything, or you will pay for a second render.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "properties": {
                  "title": {
                    "type": "string",
                    "example": "Dark Trap Type Beat"
                  },
                  "audioStoragePath": {
                    "type": "string",
                    "description": "The fileKey returned by the presign endpoint",
                    "example": "audio/1757241600000-8f14e45f-beat.mp3"
                  },
                  "video_source_type": {
                    "type": "string",
                    "enum": [
                      "youtube",
                      "upload",
                      "image"
                    ],
                    "default": "youtube"
                  },
                  "source_youtube_url": {
                    "type": "string",
                    "description": "Required when video_source_type is youtube. Must be public.",
                    "example": "https://www.youtube.com/watch?v=VIDEO_ID"
                  },
                  "startTime": {
                    "type": "number",
                    "description": "Seconds into the source video where the looping segment starts",
                    "example": 30
                  },
                  "endTime": {
                    "type": "number",
                    "description": "Seconds into the source video where the looping segment ends",
                    "example": 150
                  },
                  "uploaded_video_path": {
                    "type": "string",
                    "description": "Required when video_source_type is upload"
                  },
                  "uploaded_image_path": {
                    "type": "string",
                    "description": "Required when video_source_type is image"
                  },
                  "trackId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "v2: the id of a Track in your library (GET /api/tracks) to use as the render's audio instead of audioStoragePath (which is then optional). Must belong to you (400 \"Track not found\" otherwise)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Job created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "jobId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "creditsRemaining": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Insufficient credits. Permanent — do not retry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/jobs/{jobId}": {
      "get": {
        "tags": [
          "Jobs"
        ],
        "operationId": "getJob",
        "summary": "Get render job status",
        "description": "Poll every 10 seconds until status is complete or error; give up after 30 minutes. The montage object is present only when status is complete.",
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Job state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/jobs/retry": {
      "post": {
        "tags": [
          "Jobs"
        ],
        "operationId": "retryJob",
        "summary": "Re-queue a failed render",
        "description": "Costs no additional credits.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "jobId"
                ],
                "properties": {
                  "jobId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/jobs/delete": {
      "post": {
        "tags": [
          "Jobs"
        ],
        "operationId": "deleteJob",
        "summary": "Delete a job",
        "description": "Credits already spent are not refunded.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "jobId"
                ],
                "properties": {
                  "jobId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/montages": {
      "get": {
        "tags": [
          "Library"
        ],
        "operationId": "listMontages",
        "summary": "List finished videos, newest first",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "published",
                "unpublished"
              ],
              "default": "all"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Video list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "montages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Montage"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/publish/intent": {
      "post": {
        "tags": [
          "Publishing"
        ],
        "operationId": "createPublishIntent",
        "summary": "Queue a YouTube upload",
        "description": "Publishes the full video, a vertical Short cut from it, or both. There is one intent per montage and kind: re-posting while it is queued (or after error/cancelled) updates it in place. Once it is publishing or published, a re-post returns 409 rather than uploading a duplicate; pass force: true to deliberately re-upload a published video.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "privacy"
                ],
                "properties": {
                  "montageId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Either montageId or jobId is required"
                  },
                  "jobId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Alternative to montageId"
                  },
                  "channelId": {
                    "type": "string",
                    "description": "Optional. The UC… channelId (or the channel's id) from GET /api/me. Omit to publish to the most recently connected channel.",
                    "example": "UCxxxxxxxxxxxxx"
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Full-video title: at most 100 Unicode code points. The server rejects < and >."
                  },
                  "description": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "string",
                    "description": "Comma-separated"
                  },
                  "privacy": {
                    "type": "string",
                    "enum": [
                      "public",
                      "private",
                      "unlisted"
                    ]
                  },
                  "category": {
                    "type": "string",
                    "example": "music"
                  },
                  "thumbnailUrl": {
                    "type": "string",
                    "format": "uri"
                  },
                  "publishFull": {
                    "type": "boolean",
                    "default": true,
                    "description": "Set false with a clip to publish only the Short"
                  },
                  "clip": {
                    "type": "object",
                    "description": "Optional vertical Short cut from the same render",
                    "required": [
                      "inSeconds",
                      "outSeconds"
                    ],
                    "properties": {
                      "inSeconds": {
                        "type": "number"
                      },
                      "outSeconds": {
                        "type": "number",
                        "description": "Must be within 60 seconds of inSeconds"
                      },
                      "title": {
                        "type": "string"
                      },
                      "description": {
                        "type": "string"
                      },
                      "thumbnailUrl": {
                        "type": "string",
                        "format": "uri"
                      }
                    }
                  },
                  "force": {
                    "type": "boolean",
                    "default": false,
                    "description": "Re-upload an intent that is already published, creating a second YouTube video. Never overrides an intent that is publishing."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "intentId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "intentIds": {
                      "type": "object",
                      "properties": {
                        "full": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "short": {
                          "type": "string",
                          "format": "uuid"
                        }
                      }
                    },
                    "status": {
                      "type": "string",
                      "example": "queued"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "No usable YouTube authorization. Permanent for an agent — the account owner must reconnect at /connections.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "needsAuth": {
                          "type": "boolean"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "channelId does not match a channel connected to this account. Not an auth problem: pick a channelId from connectedChannels, or omit it.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "connectedChannels": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "channelId": {
                                "type": "string"
                              },
                              "channelName": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "An intent for this montage is already publishing (publish_in_progress: keep polling) or published (already_published: report intents[].youtubeUrl, or re-post with force). Nothing was written.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "enum": [
                            "publish_in_progress",
                            "already_published",
                            "publish_conflict"
                          ]
                        },
                        "intents": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/PublishIntent"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "get": {
        "tags": [
          "Publishing"
        ],
        "operationId": "getPublishIntents",
        "summary": "Look up publish intents",
        "description": "Exactly one selector is required. Note the parameter is `id`, not `intentId`. Poll every 15 seconds until every intent reaches published or error; give up after 30 minutes. Polling by jobId returns the full video and the Short together.",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "A single intent by its own ID"
          },
          {
            "name": "jobId",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Every intent for a render job"
          },
          {
            "name": "montageId",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Every intent for a montage"
          }
        ],
        "responses": {
          "200": {
            "description": "Intents, oldest first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "intents": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PublishIntent"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/publish/intent/retry": {
      "post": {
        "tags": [
          "Publishing"
        ],
        "operationId": "retryPublishIntent",
        "summary": "Retry a failed publish",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "intentId"
                ],
                "properties": {
                  "intentId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "The intent is still queued or publishing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/publish/intent/cancel": {
      "post": {
        "tags": [
          "Publishing"
        ],
        "operationId": "cancelPublishIntent",
        "summary": "Cancel a queued publish",
        "description": "Cancels an intent that is still queued. Cancelling a youtube_full intent also cancels the queued youtube_short that depends on it. An upload that has started can't be stopped.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "intentId"
                ],
                "properties": {
                  "intentId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled (or was already cancelled, with an empty cancelledIntentIds)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "cancelledIntentIds": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "format": "uuid"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "The intent is publishing, published, or errored and can't be cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/credits/plans": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getPlans",
        "summary": "Credit pack pricing",
        "security": [],
        "responses": {
          "200": {
            "description": "Available credit packs"
          }
        }
      }
    },
    "/api/upload/audio": {
      "post": {
        "tags": [
          "Upload"
        ],
        "operationId": "uploadAudioDirect",
        "summary": "Upload audio directly to the API domain",
        "description": "Stores the audio and returns a fileKey usable as audioStoragePath in POST /api/montage/schedule. Use this when the caller cannot reach *.r2.cloudflarestorage.com (sandboxed agents with egress allowlists). IMPORTANT: the host rejects request bodies larger than ~4.5 MB with a plain-text 413 before this handler runs, so send at most 4 MB here (see limits.maxDirectUploadBytes from GET /api/me) and use /api/upload/audio/presign for anything larger. Uploading costs no credits.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "audio"
                ],
                "properties": {
                  "audio": {
                    "type": "string",
                    "format": "binary",
                    "description": "The audio file. The legacy field name `file` is also accepted."
                  }
                }
              }
            },
            "audio/mpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "x-filename",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filename when sending a raw body; its extension determines the accepted format."
          }
        ],
        "responses": {
          "200": {
            "description": "Stored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "fileKey": {
                      "type": "string",
                      "description": "Pass to POST /api/montage/schedule as audioStoragePath"
                    },
                    "audioStoragePath": {
                      "type": "string",
                      "description": "Same value as fileKey"
                    },
                    "file": {
                      "type": "object",
                      "properties": {
                        "path": {
                          "type": "string",
                          "description": "Same value as fileKey"
                        },
                        "url": {
                          "type": "string",
                          "format": "uri"
                        },
                        "original_name": {
                          "type": "string"
                        },
                        "sanitized_name": {
                          "type": "string"
                        },
                        "storage_type": {
                          "type": "string",
                          "enum": [
                            "r2",
                            "supabase"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/youtube/templates": {
      "get": {
        "tags": [
          "Publishing"
        ],
        "operationId": "listYoutubeTemplates",
        "summary": "List saved YouTube metadata templates",
        "description": "The caller's reusable title/description/tags presets from the publish page, so an agent can reuse them instead of inventing metadata. Read-only.",
        "responses": {
          "200": {
            "description": "Templates, newest first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "templates": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/YoutubeTemplate"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/upload/thumbnail": {
      "post": {
        "tags": [
          "Publishing"
        ],
        "operationId": "uploadThumbnail",
        "summary": "Attach a custom thumbnail to a finished video",
        "description": "Multipart upload, max 5 MB. Identify the target with montageId or jobId, and send the image as either a `file` field or a `dataUrl` string.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "montageId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Either montageId or jobId is required"
                  },
                  "jobId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "file": {
                    "type": "string",
                    "format": "binary"
                  },
                  "dataUrl": {
                    "type": "string",
                    "description": "Alternative to file: a data: URL"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "frame",
                      "publish"
                    ],
                    "description": "frame: a plain image that becomes the Visual's library thumbnail. publish: a YouTube-only thumbnail (e.g. with the text overlay), stored but not shown in the library. Omitted: behaves like frame."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Thumbnail stored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "thumbnailUrl": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/tracks/uploads": {
      "post": {
        "tags": [
          "Tracks"
        ],
        "operationId": "createTrackUpload",
        "summary": "Check for a duplicate and get a presigned URL for a Track upload",
        "description": "Step 1 of 2 for adding a Track. Hash the file client-side (SHA-256) first. If the hash matches a Track you already own, no upload happens — you get that Track back instead. Otherwise you get a presigned PUT URL (valid 15 minutes) and a list of Tracks whose title looks similar to this filename (not skipped, just flagged). PUT the raw bytes to `upload.url` with Content-Type set to the mime this call normalized (not necessarily what you sent), then call POST /api/tracks/uploads/confirm — no Track exists until that call succeeds. With replaceTrackId, an identical hash for that owned Track is allowed to upload for explicit replacement.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "filename",
                  "bytes",
                  "mime",
                  "hash"
                ],
                "properties": {
                  "filename": {
                    "type": "string",
                    "description": "Extension must be .wav, .mp3, .aif, .aiff, or .flac. Max 255 characters.",
                    "example": "Nasty Work (final mix).wav"
                  },
                  "bytes": {
                    "type": "integer",
                    "description": "File size in bytes, 1 to 209715200 (200 MB)",
                    "maximum": 209715200,
                    "example": 5242880
                  },
                  "mime": {
                    "type": "string",
                    "description": "One of the enum values, or an empty/unrecognized string — it is then normalized from the extension.",
                    "enum": [
                      "audio/wav",
                      "audio/x-wav",
                      "audio/wave",
                      "audio/mpeg",
                      "audio/mp3",
                      "audio/aiff",
                      "audio/x-aiff",
                      "audio/flac",
                      "audio/x-flac"
                    ],
                    "example": "audio/wav"
                  },
                  "hash": {
                    "type": "string",
                    "description": "SHA-256 of the file contents, 64 lowercase hex characters",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "replaceTrackId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Optional existing Track id to replace after user confirmation. Must be owned by the caller. Pass the same id to presign and confirm."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Exact duplicate, or a new upload target",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "duplicate": {
                          "type": "object",
                          "properties": {
                            "trackId": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "title": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    },
                    {
                      "type": "object",
                      "properties": {
                        "upload": {
                          "type": "object",
                          "properties": {
                            "key": {
                              "type": "string",
                              "example": "audio/<userId>/<uuid>.wav"
                            },
                            "url": {
                              "type": "string",
                              "format": "uri"
                            },
                            "expiresAt": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        },
                        "similar": {
                          "type": "array",
                          "description": "Existing Tracks whose cleaned title resembles this filename",
                          "items": {
                            "type": "object",
                            "properties": {
                              "trackId": {
                                "type": "string",
                                "format": "uuid"
                              },
                              "title": {
                                "type": "string"
                              },
                              "score": {
                                "type": "number"
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Sandbox/guest accounts cannot upload — sign up for a subscription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Replacement Track not found or not owned by the caller"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/tracks/uploads/confirm": {
      "post": {
        "tags": [
          "Tracks"
        ],
        "operationId": "confirmTrackUpload",
        "summary": "Create a Track or replace its audio once the upload is confirmed in storage",
        "description": "Step 2 of 2. Call this after the PUT to the presigned URL from POST /api/tracks/uploads succeeds. This is the only call that creates a Track row — the server HEADs the object first and refuses if it is missing or the wrong size, so a browser tab closed mid-upload never leaves an orphan Track. `title` is optional (derived from the filename otherwise); `apply` is optional and every id in it is checked against your own Genres/Tags/Artists — one that isn't yours, or is the wrong property, is skipped rather than failing the call. With replaceTrackId, updates only the existing Track audio after storage verification; title, tags, relationships and plays are preserved, title/apply are ignored, and waveform/duration are regenerated. No version history is created.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key",
                  "filename",
                  "bytes",
                  "mime",
                  "hash"
                ],
                "properties": {
                  "key": {
                    "type": "string",
                    "description": "The `upload.key` returned by POST /api/tracks/uploads",
                    "example": "audio/<userId>/<uuid>.wav"
                  },
                  "filename": {
                    "type": "string",
                    "example": "Nasty Work (final mix).wav"
                  },
                  "bytes": {
                    "type": "integer",
                    "maximum": 209715200,
                    "example": 5242880
                  },
                  "mime": {
                    "type": "string",
                    "enum": [
                      "audio/wav",
                      "audio/x-wav",
                      "audio/wave",
                      "audio/mpeg",
                      "audio/mp3",
                      "audio/aiff",
                      "audio/x-aiff",
                      "audio/flac",
                      "audio/x-flac"
                    ],
                    "example": "audio/wav"
                  },
                  "hash": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "title": {
                    "type": "string",
                    "description": "Defaults to the filename, cleaned (extension stripped, separators turned into spaces)",
                    "example": "Nasty Work"
                  },
                  "apply": {
                    "type": "object",
                    "description": "\"Apply to these\" — tags the new Track. Every id must belong to you.",
                    "properties": {
                      "genreId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "tagIds": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "format": "uuid"
                        }
                      },
                      "artistId": {
                        "type": "string",
                        "format": "uuid"
                      }
                    }
                  },
                  "replaceTrackId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Optional existing Track id to replace after user confirmation. Must be owned by the caller. Pass the same id to presign and confirm."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Duplicate, or existing Track audio replaced",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "duplicate": {
                      "type": "object",
                      "properties": {
                        "trackId": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "title": {
                          "type": "string"
                        }
                      }
                    },
                    "track": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "title": {
                          "type": "string"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    },
                    "replaced": {
                      "type": "boolean",
                      "description": "True when the existing Track audio was replaced"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Track created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "track": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "title": {
                          "type": "string"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Sandbox/guest accounts cannot upload — sign up for a subscription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Replacement Track not found or not owned by the caller"
          },
          "409": {
            "description": "`upload_missing` (nothing at `key` yet) or `size_mismatch` (object size does not match `bytes`); replacement target changed concurrently, or the audio belongs to a different Track",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/tracks": {
      "get": {
        "tags": [
          "Tracks"
        ],
        "operationId": "listTracks",
        "summary": "List your Tracks, with generic filters, search, sort and pagination",
        "description": "Server-driven listing over the `track_rows` view (architecture §7, requirements §3.9). `filter` is a JSON array of {property, op, value} — every Track property filters the same way. Combine with `q` (title search) and paginate with `cursor` (opaque, from the previous page's `next_cursor`). With `group_by`, returns the matching Tracks grouped into folders instead (requirements §3.12): a Track with several values counts in each folder, Tracks with no value collect in a last folder with a null value, and `sort`, `dir`, `cursor` and `limit` are ignored. List one folder's Tracks with an `is` (or `is_empty`) filter on its value.",
        "parameters": [
          {
            "name": "filter",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "JSON-encoded array of Filter objects, e.g. `[{\"property\":\"artist\",\"op\":\"is\",\"value\":\"<id>\"}]`. Every property/op/value combination is validated; an unknown one is a 400."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Title search (case-insensitive substring)"
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "created_at",
                "title",
                "bpm",
                "key",
                "scale",
                "genre"
              ],
              "default": "created_at"
            }
          },
          {
            "name": "dir",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque; pass back the previous page's next_cursor"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            }
          },
          {
            "name": "group_by",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "artist",
                "genre",
                "key",
                "scale",
                "tag"
              ]
            },
            "description": "Return folders (grouped by this property) instead of Tracks. Search and filters apply first."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of Tracks, or the folders when `group_by` is given",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "tracks": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/TrackRow"
                          }
                        },
                        "total": {
                          "type": "integer",
                          "description": "Total matching the filters, for \"7 of 216\""
                        },
                        "next_cursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/FoldersPage"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/tracks/{id}": {
      "get": {
        "tags": [
          "Tracks"
        ],
        "operationId": "getTrack",
        "summary": "Get one Track, with per-artist relationship detail",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Track detail",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TrackDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Tracks"
        ],
        "operationId": "patchTrack",
        "summary": "Edit a Track's properties, or add/remove Artists",
        "description": "Direct fields (title/bpm/key/scale/show_on_profile), genre_id (replaces the track's single Genre value) and tag_ids (replaces the Tag set) update immediately. add_artist_ids/remove_artist_ids call bulk_tag_artist/untag_artist per artist (architecture §3.3); adding an Artist who removed this Track before is skipped, reported in `skipped`, and returns 409 `artist_removed` only when nothing else in the request changed.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Artists are added/removed through tagging (events), not set directly.",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "bpm": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 20,
                    "maximum": 400
                  },
                  "key": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 11
                  },
                  "scale": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "major",
                      "minor",
                      "ionian",
                      "dorian",
                      "phrygian",
                      "lydian",
                      "mixolydian",
                      "aeolian",
                      "locrian",
                      "harmonic_minor",
                      "melodic_minor",
                      "pentatonic",
                      "blues",
                      null
                    ]
                  },
                  "genre_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "tag_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "add_artist_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "remove_artist_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "show_on_profile": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated Track (with a `skipped` field when an add_artist_ids entry was skipped)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TrackRow"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`artist_removed` — every requested Artist add was skipped because they removed this Track before, and nothing else in the request changed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Tracks"
        ],
        "operationId": "deleteTrack",
        "summary": "Delete a Track",
        "description": "Manual and meant to be confirmed in the UI (principles §2.7: never automatic). The audio object in storage is not deleted.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/tracks/bulk": {
      "post": {
        "tags": [
          "Tracks"
        ],
        "operationId": "bulkEditTracks",
        "summary": "Edit many Tracks at once, by id or by the current filters",
        "description": "Provide `ids`, or `filter` (+ optional `q`) to act on everything matching — the same filter mapping GET /api/tracks uses. filter/q resolution is capped at 5000 Tracks.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "op"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "filter": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Filter"
                    }
                  },
                  "q": {
                    "type": "string"
                  },
                  "op": {
                    "type": "string",
                    "enum": [
                      "add_artist",
                      "remove_artist",
                      "add_tag",
                      "remove_tag",
                      "set_genre",
                      "show_on_profile",
                      "hide"
                    ]
                  },
                  "value_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "The Artist/Tag/Genre id the op acts on (required for add_artist, remove_artist, add_tag, remove_tag; optional for set_genre — omit to clear)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Counts of what happened",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BulkResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/tracks/{id}/restore": {
      "post": {
        "tags": [
          "Tracks"
        ],
        "operationId": "restoreTrackRemoval",
        "summary": "Undo an Artist's removal of a Track",
        "description": "Owner Restore (requirements §3.4): clears the removal and the Artist's old favorite/use — a fresh start. It does not re-tag the Artist.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "artist_id"
                ],
                "properties": {
                  "artist_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/tracks/{id}/taken": {
      "post": {
        "tags": [
          "Tracks"
        ],
        "operationId": "setTrackTaken",
        "summary": "Mark or clear \"Taken by\" on a Track",
        "description": "requirements §24: any Artist already in the list, or null to clear. Ends other artists' in-use state on the track and fans out `taken`/`untaken` events to every pack that currently shows it.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "artist_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/tracks/{id}/clear-use": {
      "post": {
        "tags": [
          "Tracks"
        ],
        "operationId": "clearTrackUse",
        "summary": "Clear one Artist's \"in use\" mark, without taking the Track",
        "description": "architecture §19: the small \"Clear\" next to \"Mark taken\" on each in-use row in Track Edit. Does not touch `taken_by`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "artist_id"
                ],
                "properties": {
                  "artist_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/stream/{trackId}": {
      "get": {
        "tags": [
          "Tracks"
        ],
        "operationId": "streamTrack",
        "summary": "Resolve a Track's audio to a signed URL",
        "description": "Every play resolves here (architecture §4, principles §6.2): an access check, then a 302 redirect to a signed URL valid 5 minutes. Audio is never publicly addressable. The signed URL streams; an Artist's one-tap download of the original file is `POST /api/stream/{trackId}/download`.",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "via",
            "in": "query",
            "required": true,
            "description": "Context the play happens in. An agent playing its own library uses `owner`.",
            "schema": {
              "type": "string",
              "pattern": "^(owner|owned|pack:[0-9A-Za-z]{12}|profile:[a-z0-9-]{3,40})$"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to a signed, time-limited download URL.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "description": "Signing the storage URL failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "stream_unavailable"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stream/{trackId}/download": {
      "post": {
        "tags": [
          "Pack Links"
        ],
        "operationId": "downloadTrack",
        "summary": "Download a Track's original file (and mark it In use)",
        "description": "An Artist's one-tap download from a Pack link or the producer's profile (requirements §8.10). Requires a signed-in cookie session, not a Bearer API key — agents don't act as artists (principles §3). Access is exactly Use's: the Track must be in that pack or on that profile for the caller's Artist. The call marks the Track In use and favorited (the same as `use`), logs a `downloaded` event, and returns a 5-minute signed URL that forces a download of the original file. Refused with 403 `downloads_disabled` when the producer has turned downloads off (`allowDownloads` on `PATCH /api/profile`).",
        "security": [],
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "via",
            "in": "query",
            "required": true,
            "description": "`pack:<12-char token>` or `profile:<slug>`.",
            "schema": {
              "type": "string",
              "pattern": "^(pack:[0-9A-Za-z]{12}|profile:[a-z0-9-]{3,40})$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The signed URL and file name",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri",
                      "description": "Valid 5 minutes; `Content-Disposition: attachment`"
                    },
                    "filename": {
                      "type": "string"
                    },
                    "favorited": {
                      "type": "boolean"
                    },
                    "using": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "`sign_in_required` — the client opens the sign-in sheet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`claimed_by_other` / `listener_only` / `owner_preview` / `downloads_disabled`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "description": "`download_unavailable` — signing the storage URL failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/values": {
      "get": {
        "tags": [
          "Tracks"
        ],
        "operationId": "listValues",
        "summary": "List your Artist/Genre/Tag values",
        "description": "The growable, de-duplicated property lists (requirements §3.2) that back every property's autocomplete.",
        "parameters": [
          {
            "name": "property",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "artist",
                "genre",
                "tag"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Matches label or its normalized form (case/punctuation/spacing-insensitive), limit 50"
          }
        ],
        "responses": {
          "200": {
            "description": "Matching values, ordered by label",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "values": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PropertyValue"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Tracks"
        ],
        "operationId": "createValue",
        "summary": "Add (or resolve) an Artist/Genre/Tag value",
        "description": "upsert_value (architecture §3.3): a label that normalizes to one already in the list returns the existing value instead of creating a duplicate.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "property",
                  "label"
                ],
                "properties": {
                  "property": {
                    "type": "string",
                    "enum": [
                      "artist",
                      "genre",
                      "tag"
                    ]
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created (or resolved to the existing match)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "value": {
                      "$ref": "#/components/schemas/PropertyValue"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/values/{id}": {
      "patch": {
        "tags": [
          "Tracks"
        ],
        "operationId": "renameValue",
        "summary": "Rename an Artist/Genre/Tag value",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "label"
                ],
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Renamed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "value": {
                      "$ref": "#/components/schemas/PropertyValue"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`label_taken` — another of your values already normalizes to this label",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Tracks"
        ],
        "operationId": "deleteValue",
        "summary": "Delete an Artist/Genre/Tag value",
        "description": "Blocked while an Artist has a Pack, a claim, or Tracks taken by it (architecture §19): `artist_has_packs`, `artist_is_claimed`, `artist_has_taken_tracks`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`artist_has_packs`, `artist_is_claimed`, or `artist_has_taken_tracks`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/packs": {
      "get": {
        "tags": [
          "Packs"
        ],
        "operationId": "listPacks",
        "summary": "List your Packs, newest first",
        "description": "From the `pack_rows` view (architecture §3.2). `?artist_id=` narrows to one Artist's Pack.",
        "parameters": [
          {
            "name": "artist_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Your Packs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "packs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PackRow"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Packs"
        ],
        "operationId": "sendToArtist",
        "summary": "Send to artist: tag an Artist on Tracks, from ids or from the Tracks table's current filters",
        "description": "Resolves the Artist from `artist_id`, or from `artist_name` (an existing Artist with that name is reused, otherwise one is created). Resolves the Track ids from `track_ids` (verified as yours) or from `filter`/`q` — the same filter mapping GET /api/tracks uses, capped at 5000 Tracks — then tags the Artist on them (`bulk_tag_artist`). Each Artist has one Pack, created on first use; the response returns it and its link. Tracks the Artist already removed, or that are taken by someone else, are skipped (`skipped_removed`/`skipped_taken`).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "artist_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "artist_name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80,
                    "description": "Used when artist_id is absent"
                  },
                  "track_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "filter": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Filter"
                    }
                  },
                  "q": {
                    "type": "string",
                    "description": "Title search, combined with filter"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The Artist's Pack and the tagging counts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pack": {
                      "$ref": "#/components/schemas/PackRow"
                    },
                    "url": {
                      "type": "string",
                      "description": "Absolute link to copy"
                    },
                    "added": {
                      "type": "integer"
                    },
                    "already": {
                      "type": "integer"
                    },
                    "skipped_removed": {
                      "type": "integer"
                    },
                    "skipped_taken": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/packs/{id}": {
      "get": {
        "tags": [
          "Packs"
        ],
        "operationId": "getPack",
        "summary": "Get a Pack's detail: tracks, removed tracks, claim and activity",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Pack detail",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PackDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/packs/{id}/reset-link": {
      "post": {
        "tags": [
          "Packs"
        ],
        "operationId": "resetPackLink",
        "summary": "Replace a Pack's link",
        "description": "The old link stops working. The claim and Track data are unaffected — the claim lives on the Artist, not the link (requirements §7, §25).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The new link",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "link_token": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/packs/{id}/tracks": {
      "post": {
        "tags": [
          "Packs"
        ],
        "operationId": "addPackTracks",
        "summary": "Add Tracks to a Pack (tags its Artist)",
        "description": "Tags the Pack's Artist on the Tracks (requirements §6.3).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "track_ids"
                ],
                "properties": {
                  "track_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Counts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "added": {
                      "type": "integer"
                    },
                    "already": {
                      "type": "integer"
                    },
                    "skipped_removed": {
                      "type": "integer"
                    },
                    "skipped_taken": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Packs"
        ],
        "operationId": "removePackTracks",
        "summary": "Remove Tracks from a Pack (untags its Artist)",
        "description": "Untags the Pack's Artist on the Tracks (requirements §6.4).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "track_ids"
                ],
                "properties": {
                  "track_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Removed count",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "removed": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/artists/{id}/release": {
      "post": {
        "tags": [
          "Packs"
        ],
        "operationId": "releaseArtistClaim",
        "summary": "Hand an Artist's claim back",
        "description": "Clears the account that claimed this Artist. The next sign-in on one of their Pack links claims it (requirements §19, §25) — use this when a manager claimed an Artist by mistake.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The Artist's id (a property_values id, not an account id)"
          }
        ],
        "responses": {
          "204": {
            "description": "Released (or already unclaimed)"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/p/{token}": {
      "get": {
        "tags": [
          "Pack Links"
        ],
        "operationId": "getPublicPack",
        "summary": "Open a Pack link — no sign-in required",
        "description": "Anyone with the link can listen (principles §2.6). The Artist property is never included (requirements §8.1). `favorited`/`using` on each track are present only for the artist who claimed this link. Not an agent endpoint — no Bearer key is accepted or required.",
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Za-z]{12}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The Pack",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "no-store"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicPack"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/p/{token}/events": {
      "post": {
        "tags": [
          "Pack Links"
        ],
        "operationId": "postPackEvent",
        "summary": "Record a pack open or a track play",
        "description": "Anonymous is fine — the link identifies the Artist, and a play is attributed to them either way (requirements §8.9). De-duplicated per `visit_id`: one open per visit, one play per Track per visit. Not an agent endpoint.",
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Za-z]{12}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "visit_id",
                  "type"
                ],
                "properties": {
                  "visit_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Stable for one page-load; used to de-dupe opens/plays"
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "pack_opened",
                      "track_played"
                    ]
                  },
                  "track_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Required for track_played"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Whether a new event was recorded (false when de-duped)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "recorded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/p/{token}/tracks/{trackId}/{action}": {
      "post": {
        "tags": [
          "Pack Links"
        ],
        "operationId": "postPackAction",
        "summary": "Favorite, remove, Use (or undo) a Track from a Pack link",
        "description": "Requires a signed-in cookie session, not a Bearer API key — agents don't act as artists (principles §3). Claims the link's Artist for the caller on first action, when the rules allow (requirements §25). `remove` is reversible with `undo_remove` for 30 seconds server-side (5 seconds shown in the UI).",
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Za-z]{12}$"
            }
          },
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "favorite",
                "unfavorite",
                "remove",
                "undo_remove",
                "use",
                "unuse"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The Track's new state for this Artist",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "favorited": {
                      "type": "boolean"
                    },
                    "using": {
                      "type": "boolean"
                    },
                    "removed": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_action`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "`sign_in_required` — the client should open the sign-in sheet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`claimed_by_other` / `listener_only` / `owner_preview`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "410": {
            "description": "`undo_expired` — more than 30 seconds passed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/me/inbox": {
      "get": {
        "tags": [
          "Artist Home"
        ],
        "operationId": "getMyInbox",
        "summary": "Every Pack sent to the signed-in Artist, grouped by producer",
        "description": "Cookie session only — not an agent/API-key surface (principles §3). Each producer has one pack for this Artist, titled with the producer's name (requirements §25).",
        "security": [],
        "responses": {
          "200": {
            "description": "The Inbox",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "producers": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/InboxProducer"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/me/activity": {
      "get": {
        "tags": [
          "Artist Home"
        ],
        "operationId": "getMyActivity",
        "summary": "What happened across the signed-in Artist's Packs",
        "description": "Cookie session only. Names the beat, never who took it (requirements §25). `unread` counts items newer than `profiles.activity_seen_at` (architecture §10).",
        "security": [],
        "responses": {
          "200": {
            "description": "The Activity feed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ActivityItem"
                      }
                    },
                    "unread": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/me/activity/seen": {
      "post": {
        "tags": [
          "Artist Home"
        ],
        "operationId": "postMyActivitySeen",
        "summary": "Mark the Activity tab read",
        "description": "Cookie session only. Sets `profiles.activity_seen_at = now()`, clearing the Activity tab's unread dot (requirements §25).",
        "security": [],
        "responses": {
          "200": {
            "description": "Marked read",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "activity_seen_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/me/owned": {
      "get": {
        "tags": [
          "Artist Home"
        ],
        "operationId": "getMyOwned",
        "summary": "Every Track taken by any Artist this account has claimed",
        "description": "Cookie session only. Playable regardless of the producer's \"Show on profile\" setting (requirements §24, §26).",
        "security": [],
        "responses": {
          "200": {
            "description": "The Owned shelf",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tracks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OwnedTrack"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/analytics": {
      "get": {
        "tags": [
          "Analytics"
        ],
        "operationId": "getAnalytics",
        "summary": "All-time pack analytics",
        "description": "All-time KPIs, a 30-day zero-filled daily plays series, most favorited Tracks, and every owner Pack (architecture §7, §9; requirements §11). Computed live from events/artist_tracks — never a stored counter.",
        "responses": {
          "200": {
            "description": "Analytics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "kpis": {
                      "$ref": "#/components/schemas/AnalyticsKpis"
                    },
                    "daily_plays": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DailyPlays"
                      }
                    },
                    "most_favorited": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MostFavoritedTrack"
                      }
                    },
                    "packs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PackRow"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/activity": {
      "get": {
        "tags": [
          "Analytics"
        ],
        "operationId": "getActivity",
        "summary": "The owner's activity feed across every Pack",
        "description": "Events grouped by (type, created_at, pack, artist) — a bulk action writes every row of one statement with the same timestamp, so it collapses into one row with a count (architecture §7 \"owner feed for Home and Pack detail\"; requirements §12).",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            },
            "description": "How many grouped rows to return"
          }
        ],
        "responses": {
          "200": {
            "description": "Activity feed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "activity": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OwnerActivityItem"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/youtube/stats": {
      "get": {
        "tags": [
          "Analytics"
        ],
        "operationId": "getYoutubeStats",
        "summary": "Live YouTube view counts",
        "description": "Fetched from the YouTube Data API on every call (requirements §11.2) — nothing is stored. `channels.list` for each connected channel's all-time views, `videos.list` (batched 50 ids/call) for the latest Visuals' own view counts. A 60s in-memory cache per channel limits repeat calls from several open tabs (architecture §9). `{\"connected\": false}` when no YouTube channel is connected.",
        "responses": {
          "200": {
            "description": "YouTube stats",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "connected": {
                          "type": "boolean",
                          "enum": [
                            false
                          ]
                        }
                      },
                      "required": [
                        "connected"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "connected": {
                          "type": "boolean",
                          "enum": [
                            true
                          ]
                        },
                        "total_views": {
                          "type": "integer"
                        },
                        "channels": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/YoutubeChannelStat"
                          }
                        },
                        "latest": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/YoutubeLatestVideo"
                          }
                        }
                      },
                      "required": [
                        "connected",
                        "total_views",
                        "channels",
                        "latest"
                      ]
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/u/{slug}": {
      "get": {
        "tags": [
          "Producer Profile"
        ],
        "operationId": "getProducerProfile",
        "summary": "Open a producer's profile — Artists with a claim only",
        "description": "Cookie session only, not an agent/API-key surface (principles §3). `tracks` is only those set to Show on profile and not taken by someone else (requirements §26). 404 for a bad slug or a caller with no claim on one of this producer's Artists — the same response either way, so the profile's existence is never leaked (principles §2.4).",
        "security": [],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The profile",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "no-store"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "producer": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "avatar_url": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "links": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "contact_email": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "pro": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "ipi": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "downloads": {
                          "type": "boolean",
                          "description": "The producer allows downloads"
                        }
                      }
                    },
                    "genres": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "tracks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ProfileTrack"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/u/{slug}/tracks/{trackId}/{action}": {
      "post": {
        "tags": [
          "Producer Profile"
        ],
        "operationId": "postProfileAction",
        "summary": "Favorite or Use a Track from a producer's profile",
        "description": "Requires a signed-in cookie session with a claim on one of this producer's Artists (requirements §26). No `remove` — there's no Remove on the profile. Clears any earlier removal and tags the caller's Artist, so the Track joins their Pack (architecture §19).",
        "security": [],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "favorite",
                "unfavorite",
                "use",
                "unuse"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The Track's new state for this Artist",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "favorited": {
                      "type": "boolean"
                    },
                    "using": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/profile": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getProfile",
        "summary": "Get your producer profile (requirements §26)",
        "description": "The page artists you've sent a pack to see at usemontage.com/u/<slug>. Never 404s for a missing row — an untouched profile just has empty/null fields.",
        "responses": {
          "200": {
            "description": "Your profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "profile": {
                      "$ref": "#/components/schemas/Profile"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "patch": {
        "tags": [
          "Account"
        ],
        "operationId": "updateProfile",
        "summary": "Update your producer profile",
        "description": "Every field is optional — only fields present in the body are validated and written. Changing `slug` means links already shared with the old one stop working.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "avatarUrl": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "contactEmail": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "email"
                  },
                  "links": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 10
                  },
                  "pro": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "BMI",
                      "ASCAP",
                      "SESAC",
                      "GMR",
                      "SOCAN",
                      "PRS",
                      "Other",
                      null
                    ]
                  },
                  "ipi": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 32
                  },
                  "slug": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^[a-z0-9](?:[a-z0-9-]{1,38}[a-z0-9])$"
                  },
                  "allowDownloads": {
                    "type": "boolean",
                    "description": "Let signed-in artists download the original file of any Track in their pack or on your profile (one tap, which also marks it In use). Default false (stream-only); true turns downloads on."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "profile": {
                      "$ref": "#/components/schemas/Profile"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "description": "`slug_taken` — that profile address is already in use",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "A Montage API key (mk_live_…) minted at https://www.usemontage.com/account/api-keys. Browser cookie sessions authenticate against the same endpoints."
      }
    },
    "responses": {
      "Success": {
        "description": "Success",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "success": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "BadRequest": {
        "description": "Validation error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid, revoked, or expired credentials",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Not found, or not owned by you",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limited or too many active jobs. Wait the number of seconds in Retry-After.",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            },
            "description": "Seconds to wait"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Channel": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "channelId": {
            "type": "string",
            "example": "UCxxxxxxxxxxxxx"
          },
          "channelName": {
            "type": "string"
          },
          "connectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "avatarUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "The channel's current YouTube avatar (read live, cached 10 minutes)"
          }
        }
      },
      "Me": {
        "type": "object",
        "properties": {
          "userId": {
            "type": "string",
            "format": "uuid"
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "authMethod": {
            "type": "string",
            "enum": [
              "api_key",
              "cookie"
            ]
          },
          "subscription": {
            "type": "object",
            "properties": {
              "status": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "active, trialing, canceled, or null when there has never been a subscription"
              },
              "currentPeriodEnd": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "credits": {
            "type": "object",
            "properties": {
              "balance": {
                "type": "integer"
              },
              "costPerVideo": {
                "type": "integer"
              }
            }
          },
          "youtubeChannels": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Channel"
            }
          },
          "activeJobs": {
            "type": "integer"
          },
          "limits": {
            "type": "object",
            "properties": {
              "maxConcurrentJobs": {
                "type": "integer"
              },
              "maxClipSeconds": {
                "type": "integer"
              },
              "maxAudioBytes": {
                "type": "integer"
              },
              "maxDirectUploadBytes": {
                "type": "integer",
                "description": "Largest body POST /api/upload/audio accepts; use presign above this."
              }
            }
          }
        }
      },
      "Montage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "videoUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "thumbnailUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "storageType": {
            "type": [
              "string",
              "null"
            ]
          },
          "youtubeVideoId": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "downloading",
              "processing",
              "uploading",
              "complete",
              "error"
            ]
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "errorMessage": {
            "type": "string",
            "description": "Present only when status is error"
          },
          "input": {
            "type": "object",
            "properties": {
              "videoSourceType": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "sourceYoutubeUrl": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "startTime": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "endTime": {
                "type": [
                  "number",
                  "null"
                ]
              }
            }
          },
          "montage": {
            "type": "object",
            "description": "Present only when status is complete",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "title": {
                "type": "string"
              },
              "videoUrl": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              },
              "thumbnailUrl": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              },
              "youtubeVideoId": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "publishIntents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PublishIntent"
            }
          }
        }
      },
      "PublishIntent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "youtube_full",
              "youtube_short"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "publishing",
              "published",
              "error",
              "cancelled"
            ]
          },
          "jobId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "montageId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "channelId": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "privacy": {
            "type": [
              "string",
              "null"
            ]
          },
          "youtubeVideoId": {
            "type": [
              "string",
              "null"
            ]
          },
          "youtubeUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "errorMessage": {
            "type": [
              "string",
              "null"
            ]
          },
          "attemptCount": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "YoutubeTemplate": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "tags": {
            "type": "string",
            "description": "Comma-separated, as POST /api/publish/intent expects"
          },
          "isPublic": {
            "type": "boolean"
          },
          "allowComments": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PropertyValue": {
        "type": "object",
        "description": "One entry in a growable, de-duplicated property list (Artist, Genre or Tag). Architecture §3.2.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "property": {
            "type": "string",
            "enum": [
              "artist",
              "genre",
              "tag"
            ]
          },
          "label": {
            "type": "string"
          }
        }
      },
      "TrackRow": {
        "type": "object",
        "description": "One row of the Tracks table (the `track_rows` view). Only the owner ever sees these fields.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "bpm": {
            "type": [
              "integer",
              "null"
            ]
          },
          "key": {
            "type": [
              "integer",
              "null"
            ],
            "description": "0 = C … 11 = B"
          },
          "scale": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "major",
              "minor",
              "ionian",
              "dorian",
              "phrygian",
              "lydian",
              "mixolydian",
              "aeolian",
              "locrian",
              "harmonic_minor",
              "melodic_minor",
              "pentatonic",
              "blues",
              null
            ]
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "peaks": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer"
            },
            "description": "200 waveform peaks 0-1000, set by the worker once analysed"
          },
          "show_on_profile": {
            "type": "boolean"
          },
          "audio_mime": {
            "type": "string"
          },
          "audio_bytes": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "taken_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "taken_by_label": {
            "type": [
              "string",
              "null"
            ]
          },
          "genre_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "genre": {
            "type": [
              "string",
              "null"
            ]
          },
          "tag_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "artist_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "artists": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "in_use_by": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Owner-only (principles §2.5): artist labels currently using this track"
          },
          "removed_by": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Artist labels who removed this track (requirements §3.4)"
          },
          "favorites": {
            "type": "integer"
          }
        }
      },
      "TrackDetail": {
        "type": "object",
        "description": "GET /api/tracks/{id}: the row plus per-artist relationship detail (owner only).",
        "allOf": [
          {
            "$ref": "#/components/schemas/TrackRow"
          },
          {
            "type": "object",
            "properties": {
              "relationships": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "artist_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "artist": {
                      "type": "string"
                    },
                    "tagged": {
                      "type": "boolean"
                    },
                    "removed_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    },
                    "favorited_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    },
                    "using_since": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    },
                    "use_source": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "\"profile\", \"pack\", or null"
                    }
                  }
                }
              },
              "plays": {
                "type": "integer",
                "description": "Count of track_played events for this track"
              }
            }
          }
        ]
      },
      "Filter": {
        "type": "object",
        "description": "One generic {property, op, value} filter (requirements §3.9). Every property filters the same way.",
        "required": [
          "property",
          "op"
        ],
        "properties": {
          "property": {
            "type": "string",
            "enum": [
              "title",
              "bpm",
              "key",
              "scale",
              "genre",
              "artist",
              "tag",
              "uploaded",
              "status",
              "profile"
            ]
          },
          "op": {
            "type": "string",
            "enum": [
              "contains",
              "is",
              "is_not",
              "any_of",
              "between",
              "gte",
              "lte",
              "before",
              "after",
              "within_days",
              "is_empty",
              "is_not_empty"
            ]
          },
          "value": {
            "description": "String for text/scale; number for bpm/key; [min, max] for between; id(s) for values; ISO date for before/after; integer days for within_days; \"taken\"|\"in_use\"|\"available\" for status; boolean for profile."
          }
        }
      },
      "BulkResult": {
        "type": "object",
        "properties": {
          "matched": {
            "type": "integer",
            "description": "Tracks resolved from ids, or from filter/q (capped at 5000)"
          },
          "changed": {
            "type": "integer",
            "description": "Tracks actually affected by the op"
          },
          "skipped_removed": {
            "type": "integer",
            "description": "add_artist only: tracks this Artist removed before (requirements §3.7)"
          },
          "skipped_taken": {
            "type": "integer",
            "description": "add_artist only: tracks taken by someone else"
          }
        },
        "required": [
          "matched",
          "changed"
        ]
      },
      "PackRow": {
        "type": "object",
        "description": "Owner-side pack (the `pack_rows` view). One pack per Artist; its title is the Artist's name.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "artist_id": {
            "type": "string",
            "format": "uuid"
          },
          "artist": {
            "type": "string"
          },
          "title": {
            "type": "string",
            "description": "The Artist's name"
          },
          "link_token": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "claimed": {
            "type": "boolean"
          },
          "track_count": {
            "type": "integer"
          },
          "favorites": {
            "type": "integer"
          },
          "removed": {
            "type": "integer"
          },
          "opens": {
            "type": "integer",
            "description": "Distinct visits that opened this pack's link"
          },
          "plays": {
            "type": "integer"
          },
          "last_opened_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "PackTrack": {
        "type": "object",
        "description": "One Track in a Pack's detail, with this Artist's feedback on it.",
        "allOf": [
          {
            "$ref": "#/components/schemas/TrackRow"
          },
          {
            "type": "object",
            "properties": {
              "plays": {
                "type": "integer",
                "description": "Plays of this Track on this pack's link"
              },
              "favorited": {
                "type": "boolean"
              },
              "not_played": {
                "type": "boolean",
                "description": "\"Not played yet\": no play on any of this Artist's links since the Track was tagged"
              }
            }
          }
        ]
      },
      "PackDetail": {
        "type": "object",
        "description": "GET /api/packs/{id} (requirements §5.2).",
        "allOf": [
          {
            "$ref": "#/components/schemas/PackRow"
          },
          {
            "type": "object",
            "properties": {
              "url": {
                "type": "string",
                "description": "Absolute link to copy, e.g. https://www.usemontage.com/p/<token>"
              },
              "claim": {
                "type": [
                  "object",
                  "null"
                ],
                "description": "null when the Artist is unclaimed",
                "properties": {
                  "email_hint": {
                    "type": "string",
                    "description": "Partly masked, e.g. \"future…@gmail.com\""
                  },
                  "claimed_at": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  }
                }
              },
              "tracks": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/PackTrack"
                }
              },
              "removed_tracks": {
                "type": "array",
                "description": "Tracks this Artist removed, with Restore (POST /api/tracks/{id}/restore)",
                "items": {
                  "type": "object",
                  "properties": {
                    "track_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "title": {
                      "type": "string"
                    },
                    "removed_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              },
              "activity": {
                "type": "array",
                "description": "Newest first; actions done together (a bulk tag, one Send to artist) are grouped by (type, timestamp) into one row with a count",
                "items": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "track_title": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Set only when count = 1"
                    },
                    "source": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "enum": [
                        "pack",
                        "profile",
                        "owner",
                        "agent",
                        null
                      ]
                    },
                    "at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "PublicPackTrack": {
        "type": "object",
        "description": "A Track as a pack link recipient sees it. The Artist property is never shown (requirements §8.1).",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "bpm": {
            "type": [
              "integer",
              "null"
            ]
          },
          "key": {
            "type": [
              "integer",
              "null"
            ]
          },
          "scale": {
            "type": [
              "string",
              "null"
            ]
          },
          "genre": {
            "type": [
              "string",
              "null"
            ]
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "peaks": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer"
            }
          },
          "is_new": {
            "type": "boolean",
            "description": "NEW: not played yet on this Artist's links"
          },
          "owned": {
            "type": "boolean",
            "description": "Taken by the viewer's own Artist"
          },
          "favorited": {
            "type": "boolean",
            "description": "Present only for the claimant"
          },
          "using": {
            "type": "boolean",
            "description": "Present only for the claimant"
          }
        }
      },
      "PublicPack": {
        "type": "object",
        "description": "GET /api/p/{token} — exactly what `pack_public(token)` returns. Never Artist labels (principles §2.5).",
        "properties": {
          "pack": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string",
                "description": "The producer's name"
              },
              "genres": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "producer": {
            "type": "object",
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "avatar_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "profile_slug": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Set only when the caller is the claimant"
              },
              "downloads": {
                "type": "boolean",
                "description": "The producer allows downloads; the pack page shows a download icon on each Track"
              }
            }
          },
          "viewer": {
            "type": "object",
            "properties": {
              "role": {
                "type": "string",
                "enum": [
                  "owner",
                  "artist",
                  "listener"
                ]
              },
              "claimed_by_other": {
                "type": "boolean"
              }
            }
          },
          "tracks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PublicPackTrack"
            }
          }
        }
      },
      "InboxProducer": {
        "type": "object",
        "properties": {
          "producer": {
            "type": "object",
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "avatar_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "profile_slug": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "packs": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "token": {
                  "type": "string"
                },
                "title": {
                  "type": "string",
                  "description": "The producer's name"
                },
                "count": {
                  "type": "integer"
                },
                "new": {
                  "type": "integer",
                  "description": "Tracks tagged since this Artist last played this pack"
                }
              }
            }
          }
        }
      },
      "ActivityItem": {
        "type": "object",
        "properties": {
          "producer": {
            "type": [
              "string",
              "null"
            ]
          },
          "pack_token": {
            "type": [
              "string",
              "null"
            ]
          },
          "pack_title": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "tagged",
              "pack_created",
              "pack_track_added",
              "taken"
            ]
          },
          "count": {
            "type": "integer",
            "description": "Bulk changes done together are grouped into one row"
          },
          "track_title": {
            "type": [
              "string",
              "null"
            ],
            "description": "Only set when count is 1"
          },
          "yours": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Only meaningful for type \"taken\" — never says who else took it (principles §2.5)"
          },
          "at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OwnedTrack": {
        "type": "object",
        "description": "A public Track plus the producer's name (never other Artist labels, principles §2.5).",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "bpm": {
            "type": [
              "integer",
              "null"
            ]
          },
          "key": {
            "type": [
              "integer",
              "null"
            ]
          },
          "scale": {
            "type": [
              "string",
              "null"
            ]
          },
          "genre": {
            "type": [
              "string",
              "null"
            ]
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "peaks": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer"
            }
          },
          "owned": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "favorited": {
            "type": "boolean"
          },
          "using": {
            "type": "boolean"
          },
          "producer": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ProfileTrack": {
        "type": "object",
        "description": "A public Track on a producer's profile (architecture §3.4 `profile_for_artist`). `owned` is set only when this Track was taken by the caller's own Artist here (requirements §24).",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "bpm": {
            "type": [
              "integer",
              "null"
            ]
          },
          "key": {
            "type": [
              "integer",
              "null"
            ]
          },
          "scale": {
            "type": [
              "string",
              "null"
            ]
          },
          "genre": {
            "type": [
              "string",
              "null"
            ]
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "peaks": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer"
            }
          },
          "owned": {
            "type": "boolean"
          },
          "favorited": {
            "type": "boolean"
          },
          "using": {
            "type": "boolean"
          }
        }
      },
      "AnalyticsKpis": {
        "type": "object",
        "description": "All-time, rolled up across every Pack (requirements §11.1).",
        "properties": {
          "opens": {
            "type": "integer",
            "description": "Distinct visits that opened any Pack link"
          },
          "plays": {
            "type": "integer"
          },
          "favorites": {
            "type": "integer",
            "description": "Currently favorited (tagged, not removed)"
          },
          "removed": {
            "type": "integer",
            "description": "Currently removed"
          }
        }
      },
      "DailyPlays": {
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "plays": {
            "type": "integer"
          }
        }
      },
      "MostFavoritedTrack": {
        "type": "object",
        "properties": {
          "track_id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "favorites": {
            "type": "integer"
          }
        }
      },
      "OwnerActivityItem": {
        "type": "object",
        "description": "One grouped row of the owner activity feed (architecture §7).",
        "properties": {
          "type": {
            "type": "string",
            "description": "A raw events.type value"
          },
          "count": {
            "type": "integer"
          },
          "artist": {
            "type": [
              "string",
              "null"
            ]
          },
          "track_title": {
            "type": [
              "string",
              "null"
            ],
            "description": "Set only when count is 1"
          },
          "pack_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "pack_token": {
            "type": [
              "string",
              "null"
            ]
          },
          "pack_title": {
            "type": [
              "string",
              "null"
            ],
            "description": "The Artist's name"
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "pack",
              "profile",
              "owner",
              "agent",
              null
            ]
          },
          "at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "YoutubeChannelStat": {
        "type": "object",
        "properties": {
          "channel_id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "views": {
            "type": "integer"
          }
        }
      },
      "YoutubeLatestVideo": {
        "type": "object",
        "properties": {
          "visual_id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "youtube_video_id": {
            "type": "string"
          },
          "views": {
            "type": "integer"
          },
          "published_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "thumbnail_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          }
        }
      },
      "Profile": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "avatarUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "contactEmail": {
            "type": [
              "string",
              "null"
            ]
          },
          "links": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 10
          },
          "pro": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "BMI",
              "ASCAP",
              "SESAC",
              "GMR",
              "SOCAN",
              "PRS",
              "Other",
              null
            ]
          },
          "ipi": {
            "type": [
              "string",
              "null"
            ]
          },
          "slug": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-z0-9](?:[a-z0-9-]{1,38}[a-z0-9])$",
            "description": "usemontage.com/u/<slug>; unique"
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "allowDownloads": {
            "type": "boolean",
            "description": "Whether artists may download your Tracks' original files (default false)"
          }
        }
      },
      "TrackFolder": {
        "type": "object",
        "required": [
          "value",
          "label",
          "count",
          "cover_track_ids"
        ],
        "properties": {
          "value": {
            "type": [
              "string",
              "integer",
              "null"
            ],
            "description": "What the matching filter takes: an id (artist, genre, tag), 0-11 (key), a scale name. null is the folder of Tracks with no value (filter op is_empty)."
          },
          "label": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "cover_track_ids": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "The first few Track ids in the folder, for its cover."
          }
        }
      },
      "FoldersPage": {
        "type": "object",
        "required": [
          "folders",
          "total",
          "counts",
          "truncated"
        ],
        "properties": {
          "folders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TrackFolder"
            }
          },
          "total": {
            "type": "integer",
            "description": "Tracks matching the filters, each counted once."
          },
          "counts": {
            "type": "object",
            "description": "How many folders each property would make.",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "truncated": {
            "type": "boolean",
            "description": "True when more than 5000 Tracks matched, so only the newest 5000 were grouped."
          }
        }
      }
    }
  }
}
