The association between caffeine and diabetic retinopathy (DR) risk remains controversial. This study aims to examine the association between urinary caffeine and caffeine metabolites and self-reported DR risk in US individuals with diabetes. This cross-sectional study enrolled 535 participants with diabetes from the National Health and Nutrition Examination Survey (NHANES) 2009–2014. The high-performance liquid chromatography-electrospray ionization-tandem quadrupole mass spectrometry (HPLC–ESI–MS/MS) and internal standards labeled with stable isotopes were used to measure urinary caffeine and fourteen of its metabolites. Urinary caffeine and its metabolites levels were calibrated with urine creatinine for analysis. Caffeine and its metabolites were analyzed as continuous variables and categorical variables (≤ 50% or > 50%). Weighted logistic regression models were used to calculate odds ratios (OR) and 95% confidence intervals (CI). Subgroup analysis by sex was conducted. After adjusting for age, sex, race, BMI, smoking, alcohol drinking, duration of diabetes, glycated hemoglobin, hypertension, and total energy intake, ln-transformed 1-methyluric acid (1-MU) (OR = 1.27, 95% CI, 1.05 to 1.56, P = 0.016) and 5-acetylamino-6-amino-3-methyluracil (AAMU) (OR = 1.16, 95% CI, 1.01 to 1.34, P = 0.043) were associated with an increased DR risk. In median analysis, compared to lower levels (≤ 50%), higher levels (> 50%) of 1,7-dimethyluric acid (1,7-DMU) (OR = 1.92, 95% CI, 1.20 to 3.09, P = 0.008), caffeine (OR = 2.00, 95% CI, 1.27 to 3.16, P = 0.004), and AAMU (OR = 1.48, 95% CI, 1.04 to 2.10, P = 0.029) were associated with an increased DR risk. Sex-based analysis showed that ln-transformed 1-MU (OR = 1.48, 95% CI, 1.10 to 1.98, P = 0.012), 1,3,7-TMU (OR = 1.24, 95% CI, 1.04 to 1.49, P = 0.018) and caffeine (OR = 1.29, 95% CI, 1.03 to 1.60, P = 0.028) were associated with an increased DR risk in males. Compared to lower levels (≤ 50%), higher levels (> 50%) of 1,7-DMU (OR = 2.75, 95% CI, 1.33 to 5.70, P = 0.008), 1,3,7-TMU (OR = 2.26, 95% CI, 1.02 to 5.01, P = 0.044), caffeine (OR = 3.23, 95% CI, 1.53 to 6.82, P = 0.003), and AAMU (OR = 2.93, 95% CI, 1.16 to 7.40, P = 0.024) were associated with an increased DR risk in males. This study indicated that high urinary levels of 1-MU, 1,7-DMU, 1,3,7-TMU, caffeine and AAMU were associated with an increased risk of DR in US males with DM. Prospective studies are needed to verify these findings.