The response function of CdTe detectors used in a hard X-ray spectrometer system (HXRS) on the TCV tokamak fusion experiment is modeled based on the measured energy spectra from multiple gamma-ray sources. The response function consists of an asymmetric Gaussian photopeak, an exponentially inclined shelf structure below the photopeak, and CdTe escape peaks. It is demonstrated that the measured energy spectra of radioactive sources can be correctly reconstructed using this response function. This model is applied to a hard X-ray synthetic diagnostic used to convert a modeled electron distribution function to a measured hard X-ray signal, for the study of energetic electrons in the TCV tokamak.