Algebraic aspects of the computation of partition functions for quantum gravity and black holes in AdS3 are discussed. We compute the sub-leading quantum corrections to the Bekenstein–Hawking entropy. It is shown that the quantum corrections to the classical result can be included systematically by making use of the comparison with conformal field theory partition functions, via the AdS3/CFT2 correspondence. This leads to a better understanding of the role of modular and spectral functions, from the point of view of the representation theory of infinite-dimensional Lie algebras. Besides, the sum of known quantum contributions to the partition function can be presented in a closed form, involving the Patterson–Selberg spectral function. These contributions can be reproduced in a holomorphically factorized theory whose partition functions are associated with the formal characters of the Virasoro modules. We propose a spectral function formulation for quantum corrections to the elliptic genus from supergravity states.