  We develop a rigorous theory of radiative transitions in a nanocavity coupled
to incoherently pumped light emitters in a fully quantized picture using the
Keldysh formalism, which accounts for a collectively developed macroscopic
polarization of the gain medium and the polaritonic transformation of the
cavity mode caused by it. Incorporating many-body effects into densities of
states and nonuniform population functions, we express the radiative transition
rates as golden-rule-like integrals, which gives the possibility to directly
evaluate the laser lineshape from rate equations. In its limiting cases, the
developed model agrees with the semiclassical Maxwell-Bloch equations and the
theory of radiation of a single emitter in a cavity. Finally, we provide
concise closed-form expressions for the total spontaneous and stimulated
emission rates in a nanolaser, highlighting the gain-dependent Purcell
enhancement and breakdown of Einstein's relations.
