We carry out convergence and error analysis of the scalar auxiliary variable (SAV) methods for $L^2$ and $H^{-1}$ gradient flows with a typical form of free energy. We first derive $H^2$ bounds, under certain assumptions suitable for both the gradient flows and the SAV schemes, which allow us to establish the convergence of the SAV schemes under mild conditions. We then derive error estimates with further regularity assumptions. We also discuss several other gradient flows, which cannot be cast in the general framework used in this paper, but for which convergence and error analysis can still be established using a similar procedure.