Background Suicide is a severe health problem, with high rates in individuals with addiction. Considering the lack of studies exploring suicide predictors in this population, we aimed to investigate factors associated with attempted suicide in inpatients diagnosed with cocaine use disorder using two analytical approaches. Methods This is a cross-sectional study using a secondary database with 247 men and 442 women hospitalized for cocaine use disorder. Clinical assessment included the Addiction Severity Index, the Childhood Trauma Questionnaire, and the Structured Clinical Interview for the Diagnostic and Statistical Manual of Mental Disorders, totalling 58 variables. Descriptive Poisson regression and predictive Random Forest algorithm were used complementarily to estimate prevalence ratios and to build prediction models, respectively. All analyses were stratified by gender. Results The prevalence of attempted suicide was 34% for men and 50% for women. In both genders, depression (PR M = 1.56, PR W = 1.27) and hallucinations (PR M = 1.80, PR W = 1.39) were factors associated with attempted suicide. Other specific factors were found for men and women, such as childhood trauma, aggression, and drug use severity. The men's predictive model had prediction statistics of AUC = 0.68, Acc. = 0.66, Sens. = 0.82, Spec. = 0.50, PPV = 0.47 and NPV = 0.84. This model identified several variables as important