Designing a permanent magnet with reduced critical rare earth content is of paramount importance in the development of cost effective modern technologies. Here, by performing comprehensive first-principles calculations we investigate the potential avenues for reducing the critical rare earth content in Sm2Fe17N3 and Sm2Fe17C3 by La/Ce substitution at Sm site. The calculated magnetic properties of base compounds are in good agreement with the previous low temperature (4.2 K) experimental measurements, and show a large axial anisotropy. Although La/Ce substitution results in slight reduction of magnetic anisotropy, the magnetic moments of Fe atoms mostly remain unchanged. In particular large axial anisotropies of 7.2, and 4.1 MJ/m 3 are obtained for SmCeFe17N3, and SmLaFe17N3, respectively. These values of anisotropies are comparable to the state of the art permanent magnet Nd2Fe14B. The foremost limitation of Sm2Fe17X3 magnets for practical application is the formation nitrogen/carbon vacancies at high temperatures. By calculating the N(C) vacancy formation energy we show that La/Ce substitution enhances the vacancy formation energy. This will likely improve the thermodynamic stability of these alloys at high temperatures. Therefore, La/Ce-substituted Sm2Fe17C3, and Sm2Fe17N3 compounds are promising candidates for high-performance permanent magnets with substantially reduced rare earth content.