A spaceborne hard X-ray spectrometer, composed of an array of 99 scintillation detectors and associated readout electronics, has been developed for the hard X-ray imager (HXI). The HXI is one of the three payloads onboard the advanced space-based solar observatory (ASO-S), which is scheduled to be launched in early 2022 as the first Chinese solar satellite. $$\hbox {LaBr}_3$$ LaBr3 scintillators and photomultiplier tubes with a super bialkali cathode are used to achieve an energy resolution better than 20% at 30 keV. Further, a new multi-channel charge-sensitive readout application-specific integrated circuit guarantees high-frequency data acquisition with low power consumption. This paper presents a detailed design of the spectrometer for the engineering model of the HXI and discusses its noise and linearity performance.