Abstract Future data from galaxy redshift surveys, combined with high-resolutions maps of the cosmic microwave background, will enable measurements of the pairwise kinematic Sunyaev–Zel’dovich (kSZ) signal with unprecedented statistical significance. This signal probes the matter-velocity correlation function, scaled by the average optical depth (τ) of the galaxy groups and clusters in the sample, and is thus of fundamental importance for cosmology. However, in order to translate pairwise kSZ measurements into cosmological constraints, external constraints on τ are necessary. In this work, we present a new model for the intracluster medium, which takes into account star formation, feedback, non-thermal pressure, and gas cooling. Our semi-analytic model is computationally efficient and can reproduce results of recent hydrodynamical simulations of galaxy cluster formation. We calibrate the free parameters in the model using recent X-ray measurements of gas density profiles of clusters, and gas masses of groups and clusters. Our observationally calibrated model predicts the average (i.e., the integrated τ within a disk of size R 500) to better than 6% modeling uncertainty (at 95% confidence level). If the remaining uncertainties associated with other astrophysical uncertainties and X-ray selection effects can be better understood, our model for the optical depth should break the degeneracy between optical depth and cluster velocity in the analysis of future pairwise kSZ measurements and improve cosmological constraints with the combination of upcoming galaxy and CMB surveys, including the nature of dark energy, modified gravity, and neutrino mass.