Patients with gastrointestinal surgery have a higher incidence of infection-related complications than the rest of those who undergo clean cut surgery. It can lead to a worse prognosis for patients. This study aimed to assess the association between glycemic variability (GV) and postoperative infection-related complications of gastrointestinal cancer patients. A total of 438 patients were included in this study. Using univariate and multivariate regression analyses, the risk factors for postoperative complications were determined. And nomogram prediction models were constructed through machine learning. The performance of the nomogram was assessed with respect to the calibration curves. Univariate and multivariate regression analysis showed that high GV on post operation day (POD)1 (P <
.001), high leukocytes on POD4 (P = .003 <
.01) and alcohol consumption (P = .005 <
.01) were independent risk factors for postoperative infection-related complications in patients with gastrointestinal cancers. The area under the curve (AUC) showed that these 3 prediction models established through logistic regression (AUC = 0.81), XGBoost (AUC = 0.82) and random forest (AUC = 0.78) all performed well. Our study confirmed that higher GV on POD1 were independent risk factors for postoperative infection-related complications within 30 days of surgery in patients with gastrointestinal cancers. And the nomogram prediction model confirmed its capable for predicting infection-related complications.