The burgeoning potential of hydrogen as a future clean energy source has spurred intense research into hydrogen storage solutions. Novel hydride perovskite materials aside metal hydride are at the forefront of this effort, engaging researchers worldwide. This study utilizes Ab-initio calculations based on density functional theory (DFT) implemented in VASP to compare the electrical, elastic, thermodynamic, and optical properties of cubic KXH3 (X = Mg, Be) compounds. Generalized gradient approximation (GGA) with the Perdew-Burke-Ernzrhof (PBE) scheme is employed for optimization. Our calculations agree well with previously reported results. However, the tolerance factor suggests KBeH3 may not be stable in the cubic form. The electronic structure reveals KMgH3 to be semiconductive, while KBeH3 exhibits metallic behavior. Both compounds exhibit mechanical stability within the study. Optical properties are also investigated, showing suitability for hydrogen storage in the low energy range. Additionally, the mechanical parameters satisfy the Born stability criterion, indicating good mechanical stability for both compounds. Finally, the gravimetric ratios for hydrogen storage are calculated as 5.86 wt% and 4.52 wt% for KMgH3 and KBeH3, respectively. These high values suggest both compounds hold significant promise for diverse renewable energy applications and long-term hydrogen fuel storage.