Long-term prescription opioid use is associated both with new-onset and recurrence of depression. Whether chronic opioid use interferes with depression management has not been reported, therefore we determined whether patients' longer duration of opioid use and higher opioid dose are associated with new-onset treatment resistant depression (TRD) after controlling for confounding from pain and other variables. Data was obtained from Veteran Health Administration (VHA) de-identified patient medical records. We used a retrospective cohort design from 2000–2012. Eligible subjects (n = 6169) were 18–80 years of age, free of cancer and HIV, diagnosed with depression and opioid-free for the 24-month interval prior to the observation period. Duration of a new prescription for opioid analgesic was categorized as 1–30 days, 31–90 days and > 90 days. Morphine-equivalent dose (MED) during follow-up categorized as ≤ 50 mg versus > 50 mg per day. Pain and other sources of confounding were controlled by propensity scores and inverse probability of treatment weighting. Cox proportional hazard models were computed to estimate the association between duration and dose of opioid and onset of TRD. After controlling for confounding by weighting data, opioid use for 31–90 days and for > 90 days, compared to 1–30 days, was significantly associated with new onset TRD (HR = 1.25; 95% CI: 1.09‐1.45 and HR = 1.52; 95% CI: 1.32‐1.74, respectively). MED was not associated with new onset TRD. The risk of developing TRD increased as time spent on opioid analgesics increased. Long-term opioid treatment of chronic pain may interfere with treatment of depression.