We formulate an ab initio downfolding scheme for electron-phonon coupled systems. In this scheme, we calculate partially renormalized phonon frequencies and electron-phonon coupling, which include the screening effects of high-energy electrons, to construct a realistic Hamiltonian consisting of low-energy electron and phonon degrees of freedom. We show that our scheme, which we call constrained density-functional perturbation theory (cDFPT), can be implemented by slightly modifying the conventional DFPT, which is one of the standard methods to calculate phonon properties from first principles. Our scheme can be applied to various phonon-related problems, such as superconductivity, electron and thermal transport, thermoelectricity, piezoelectricity, dielectricity and multiferroicity. We believe that the cDFPT provides a firm basis for the understanding of the role of phonons in strongly correlated materials. Here, we apply the scheme to the fullerene superconductors and discuss how the realistic low-energy Hamiltonian is constructed.