Background: Drug checking services are becoming increasingly popular. Despite the significant variability in fentanyl concentrations observed in the unregulated opioid supply, quantifying fentanyl concentrations using community drug checking technologies remains challenging. This study reports the development of the first machine learning model to classify and quantify multiple fentanyl analogues in community drug checking samples, using data from British Columbia, Canada.
Methods: Drug checking samples from harm reduction sites using Fourier-transform infrared spectroscopy were forwarded for laboratory analysis at Health Canada's Drug Analysis Service. Using gold-standard quantitative nuclear magnetic resonance results, we developed a machine learning pipeline to classify and quantify fentanyl and fluorofentanyl in unregulated drug samples.
Results: Over a nearly six-year period, 131,096 drug checks occurred at British Columbia harm reduction sites and 2032 unique drug samples were forwarded for laboratory analysis. A total of 974 training samples were used, each containing varying amounts of fentanyl or fluorofentanyl. Model performance depended on sample composition: ridge regression produced the most accurate fentanyl estimates in absence of fluorofentanyl, while random forest performed better in mixed-analogue samples. A screening model allowed us to combine these into a hybrid pipeline, improving estimates for both fentanyl (mean average error=3.74; R2=0.94) and fluorofentanyl (mean average error=1.22; R2=0.97).
Discussion: Our study shows that machine learning models for fentanyl quantification can be used to augment traditional community drug checking technologies. However, any practical use as a point-of-care tool should be accompanied by clear communication of uncertainty to ensure predictions support, rather than unintentionally undermine, harm reduction goals.
Keywords: Drug checking; Fentanyl; Harm reduction; Machine learning.
© 2026 The Authors.