Objective Opioid use disorder (OUD) is a chronic relapsing disorder with a problematic pattern of opioid use, affecting nearly 27 million people worldwide. Machine learning (ML)-based prediction of OUD may lead to early detection and intervention. However, most ML prediction studies were not based on representative data sources and prospective validations, limiting their potential to predict future new cases. In the current study, we aimed to develop and prospectively validate an ML model that could predict individual OUD cases based on representative large-scale health data. Method We present an ensemble machine-learning model trained on a cross-linked Canadian administrative health data set from 2014 to 2018 ( n = 699,164), with validation of model-predicted OUD cases on a hold-out sample from 2014 to 2018 ( n = 174,791) and prospective prediction of OUD cases on a non-overlapping sample from 2019 ( n = 316,039). We used administrative records of OUD diagnosis for each subject based on International Classification of Diseases (ICD) codes. Results With 6409 OUD cases in 2019 (mean [SD], 45.34 [14.28], 3400 males), our model prospectively predicted OUD cases at a high accuracy (balanced accuracy, 86%, sensitivity, 93%; specificity 79%). In accord with prior findings, the top risk factors for OUD in this model were opioid use indicators and a history of other substance use disorders. Conclusion Our study presents an individualized prospective prediction of OUD cases by applying ML to large administrative health datasets. Such prospective predictions based on ML would be essential for potential future clinical applications in the early detection of OUD.