We present detailed calculations of the prompt spectrum of gamma-ray bursts ( GRBs ) predicted within the fireball model framework , where emission is due to internal shocks in an expanding relativistic wind . Our time dependent numerical model describes cyclo-synchrotron emission and absorption , inverse and direct Compton scattering , and e ^ { \pm } pair production and annihilation ( including the evolution of high energy electro-magnetic cascades ) . It allows , in particular , a self-consistent calculation of the energy distribution of e ^ { \pm } pairs produced by photon annihilation , and hence a calculation of the spectra resulting when the scattering optical depth due to pairs , \tau _ { \pm } , is high . We show that emission peaks at \sim 1 MeV for moderate to large \tau _ { \pm } , reaching \tau _ { \pm } \sim 10 ^ { 2 } . In this regime of large compactness we find that ( i ) A large fraction of shock energy can escape as radiation even for large \tau _ { \pm } ; ( ii ) The spectrum depends only weakly on the magnetic field energy fraction ; ( iii ) The spectrum is hard , \varepsilon ^ { 2 } dN / d \varepsilon \propto \varepsilon ^ { \alpha } with 0.5 < \alpha < 1 , between the self absorption ( \varepsilon _ { ssa } = 10 ^ { 0.5 \pm 0.5 } \mbox { keV } ) and peak ( \varepsilon _ { peak } = 10 ^ { 0.5 \pm 0.5 } \mbox { MeV } ) photon energy , ( iv ) and shows a sharp cutoff at \sim 10 MeV ; ( v ) Thermal Comptonization leads to emission peaking at \varepsilon _ { peak } \gtrsim 30 MeV , and can not therefore account for observed GRB spectra . For small compactness , spectra extend to > 10 GeV with flux detectable by GLAST , and the spectrum at low energy depends on the magnetic field energy fraction . Comparison of the flux at \sim 1 GeV and \sim 100 keV may therefore allow to determine the magnetic field strength . For both small and large compactness , the spectra depend only weakly on the spectral index of the energy distribution of accelerated electrons .