We aim at deriving the molecular abundances and temperatures of the hot molecular cores in the high-mass star-forming region NGC 6334I and consequently deriving their physical and astrochemical conditions. In the framework of the Herschel guaranteed time key program CHESS, NGC 6334I is investigated by using HIFI aboard the Herschel Space Observatory. A spectral line survey is carried out in the frequency range 480-1907 GHz, and auxiliary interferometric data from the SMA in the 230 GHz band provide spatial information for disentangling the different physical components contributing to the HIFI spectrum. The spectral lines are identified with the aid of former surveys and spectral line catalogs. The observed spectrum is then compared to a simulated synthetic spectrum with XCLASS, assuming local thermal equilibrium, and best fit parameters are derived using the model optimization package MAGIX. A total of 46 molecules are identified, with 31 isotopologues, resulting in about 4300 emission and absorption lines. High- energy levels of the dominant emitter methanol and vibrationally excited HCN are detected. The number of unidentified lines remains low with 75, or less than 2 percent of the lines detected. The modeling suggests that several spectral features need two or more components to be fitted properly. Other components could be assigned to cold foreground clouds or to outflows, most visible in the SiO emission. A chemical variation between the two embedded hot cores is found, with more N-bearing molecules identified in SMA1 and O-bearing molecules in SMA2. Spectral line surveys give powerful insights into the study of the interstellar medium. Different molecules trace different physical conditions like the inner hot core, the envelope, the outflows or the cold foreground clouds. The derived molecular abundances provide further constraints for astrochemical models.