Some opiates are legal. I don’t think there are any available over the counter in the US, but there are plenty of countries where you can get codeine in some form without a prescription. Other opiates are prescribed for higher levels of pain. Pretty much all the good painkillers are opiates really. I’m on codeine right now, trying to get rid of a headache.