BackgroundBreast cancer brain metastases (BCBM) are the most fatal, with limited survival in all breast cancer distant metastases. These patients are deemed to be incurable. Thus, survival time is their foremost concern. However, there is a lack of accurate prediction models in the clinic. What’s more, primary surgery for BCBM patients is still controversial.MethodsThe data used for analysis in this study was obtained from the SEER database (2010–2019). We made a COX regression analysis to identify prognostic factors of BCBM patients. Through cross-validation, we constructed XGBoost models to predict survival in patients with BCBM. Meanwhile, a BCBM cohort from our hospital was used to validate our models. We also investigated the prognosis of patients treated with surgery or not, using propensity score matching and K–M survival analysis. Our results were further validated by subgroup COX analysis in patients with different molecular subtypes.ResultsThe XGBoost models we created had high precision and correctness, and they were the most accurate models to predict the survival of BCBM patients (6-month AUC = 0.824, 1-year AUC = 0.813, 2-year AUC = 0.800 and 3-year survival AUC = 0.803). Moreover, the models still exhibited good performance in an externally independent dataset (6-month: AUC = 0.820; 1-year: AUC = 0.732; 2-year: AUC = 0.795; 3-year: AUC = 0.936). Then we used Shiny-Web tool to make our models be easily used from website. Interestingly, we found that the BCBM patients with an annual income of over USD$70,000 had better BCSS (HR = 0.523, 95%CI 0.273–0.999, P < 0.05) than those with less than USD$40,000. The results showed that in all distant metastasis sites, only lung metastasis was an independent poor prognostic factor for patients with BCBM (OS: HR = 1.606, 95%CI 1.157–2.230, P < 0.01; BCSS: HR = 1.698, 95%CI 1.219–2.365, P < 0.01), while bone, liver, distant lymph nodes and other metastases were not. We also found that surgical treatment significantly improved both OS and BCSS in BCBM patients with the HER2 + molecular subtypes and was beneficial to OS of the HR−/HER2− subtype. In contrast, surgery could not help BCBM patients with HR + /HER2− subtype improve their prognosis (OS: HR = 0.887, 95%CI 0.608–1.293, P = 0.510; BCSS: HR = 0.909, 95%CI 0.604–1.368, P = 0.630).ConclusionWe analyzed the clinical features of BCBM patients and constructed 4 machine-learning prognostic models to predict their survival. Our validation results indicate that these models should be highly reproducible in patients with BCBM. We also identified potential prognostic factors for BCBM patients and suggested that primary surgery might improve the survival of BCBM patients with HER2 + and triple-negative subtypes.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12967-023-04277-2.