In this paper, shunt active power filter (SAPF) is designed to address the problem of current harmonics in the source current arising from a nonlinear load and improve the quality of electric power. That will be by compensating reactive power and harmonic currents. The PI controller responsible for DC-link energy storage tuning was developed using the LΓ©vy flight distribution algorithm (LFA). It is a novel, previously unused optimization approach to suggest relative gain Kp and integration gain Ki gain values for the PI controller. This approach aims to get the best dynamic performance of SAPF, speed up the convergence rate, get the fastest best stability and bypass constant voltage advancement for DC-link. The model was tested and implemented in MATLAB simulation software. The result of total harmonic distortion THD showed the efficiency of this method compared with the results of traditional PI. The design of the model in the current reference frame was based on instantaneous reactive power (pq) theory.