Objective Pain is experienced by most patients with cancer and opioids are a cornerstone of management. Our objectives were (1) to identify patterns or trajectories of long-term opioid therapy (LTOT) and their correlates among patients with and without cancer and (2) to assess the association between trajectories and risk for opioid overdose, considering the potential moderating role of cancer.Methods and analysis We conducted a retrospective cohort study among individuals in the US Veterans Health Administration database with incident LTOT with and without cancer (N=44 351; N=285 772, respectively) between 2010 and 2017. We investigated the relationship between LTOT trajectory and all International Classification of Diseases (ICD)-9-defined and ICD-10-defined accidental and intentional opioid-related overdoses.Results Trajectories of opioid receipt observed in patients without cancer and replicated in patients with cancer were: low-dose/stable trend, low-dose/de-escalating trend, moderate-dose/stable trend, moderate-dose/escalating with quadratic downturn trend and high-dose/escalating with quadratic downturn trend. Time to first overdose was significantly predicted by higher-dose and escalating trajectories; the two low-dose trajectories conferred similar, lower risk. Conditional HRs (99% CI) for the moderate-dose, moderate-dose/escalating with quadratic downturn and high-dose/escalating with quadratic downturn trends were 1.84 (1.18 to 2.85), 2.56 (1.54 to 4.25) and 2.41 (1.37 to 4.26), respectively. Effects of trajectories on time to overdose did not differ by presence of cancer; inferences were replicated when restricting to patients with stage 3/4 cancer.Conclusion Patients with cancer face opioid overdose risks such as patients without cancer. Future studies should seek to expand and address our knowledge about opioid risk in patients with cancer.