ImportancePrenatal opioid exposure (POE) may alter with fetal development of the immune system, which may influence long-term health and susceptibility to immune-related conditions.ObjectiveTo compare the risk of hospitalization and emergency department presentation for immune-related conditions in children with and without POE.Design, Setting, and ParticipantsThis retrospective, population-based cohort study used linked administrative health records of all children born in Western Australia between January 1, 2003, and December 31, 2018 (N = 401 462).ExposurePrenatal exposure to prescription opioids (overall and by trimester), neonatal abstinence syndrome diagnosis, and opioid indication (pain or opioid use disorder [OUD]).Main Outcomes and MeasuresThe main outcome was hospital admissions and emergency department presentations during which a child was diagnosed with an immune-related condition, including infections, conditions associated with an overactive immune system (eg, asthma, eczema, and allergy and anaphylaxis), and autoimmune diseases diagnosed before age 5 years or June 30, 2020. Data were analyzed between August 30, 2022, and February 27, 2023.ResultsNeonates with POE (1656 [0.4%]; mean [SD] gestational age, 37.7 [2.1] weeks; 836 females [50.5%]; 820 males [49.5%]) were more likely to be born preterm, have low birth weight for gestational age, and be coexposed to cigarette smoke compared with nonexposed neonates. Perinatal opioid exposure was associated with an increased risk of perinatal infection (adjusted odds ratio [AOR], 1.62; 95% CI, 1.38-1.90) and eczema and dermatitis (AOR, 11.91; 95% CI, 9.84-14.41) compared with nonexposure. Neonatal abstinence syndrome was also associated with both conditions (AOR, 2.91 [95% CI, 2.36-3.57] and 31.11 [95% CI, 24.64-39.28], respectively). Prenatal opioid exposure was also associated with an increased risk of childhood asthma (adjusted hazard ratio [AHR], 1.44; 95% CI, 1.16-1.79), but not allergies and anaphylaxis. It was also associated with an increased risk of childhood eczema and dermatitis, but only in children with POE from opioids used to treat OUD (AHR, 1.47; 95% CI, 1.08-1.99) rather than pain. In contrast, POE from opioids used for pain was associated with an increased risk of infection (AHR, 1.44; 95% CI, 1.32-1.58), but POE to opioids used to treat OUD was not. Autoimmune conditions were rare and were not observed to be associated with POE.Conclusions and RelevanceIn this cohort study, POE was associated with an increased risk of infection, eczema and dermatitis, and asthma, but not allergies and anaphylaxis or autoimmune conditions. These findings highlight the importance of further study of opioid-induced immune changes during pregnancy, the potential impact on long-term health in exposed children, and the mechanisms of opioid-induced immune dysregulation.