BackgroundGastric cancer is the third leading cause of death from cancer worldwide and has a poor prognosis. Practical risk scores and prognostic models for gastric cancer are lacking. While immunotherapy has succeeded in some cancers, few gastric cancer patients benefit from immunotherapy. Immune genes and the tumor microenvironment (TME) are essential for cancer progression and immunotherapy response. However, the roles of immune genes and the tumor microenvironment in immunotherapy remain unclear. The study aimed to construct a prognostic prediction model and identify immunotherapeutic targets for gastric cancer (GC) patients by exploring immune genes and the tumor microenvironment.ResultsAn immune-related risk score (IRRS) model, including APOH, RNASE2, F2R, DEFB126, CXCL6, and CXCL3 genes, was constructed for risk stratification. Patients in the low-risk group, which was characterized by elevated tumor mutation burden (TMB) have higher survival rate. The risk level was remarkably correlated with tumor-infiltrating immune cells (TIICs), the immune checkpoint molecule expression, and immunophenoscore (IPS). CXCL3 and CXCL6 were significantly upregulated in gastric cancer tissues compared with normal tissues using the UALCAN database and RT-qPCR. The nomogram showed good calibration and moderate discrimination in predicting overall survival (OS) at 1-, 3-, and 5- year for gastric cancer patients using risk-level and clinical characteristics.ConclusionOur findings provided a risk stratification and prognosis prediction tool for gastric cancer patients and further the research into immunotherapy in gastric cancer.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12859-023-05312-1.