In this paper, a DC-link voltage tuning algorithm is introduced to control the shunt active filter (SAF) with sinusoidal and trapezoidal power supplies. The purpose of the proposed optimization algorithm is for tuning the PI controller and reducing the harmonics level. Artificial bee colony (ABC) algorithm is introduced for tuning the gain of the controller and the voltage variation of power converter by using PWM pulses. It regulates the DC-link voltage as per the signal harmonics and the active power loss of the system is reduced. Therefore, the accurate compensation current is injected by the SAF devices. The proposed ABC-PI controller-based harmonic compensation method is implemented in MATLAB/Simulink platform. Then, the Total Harmonic Distortion (THD) and the power factor are evaluated. The results of the proposed method are compared with PI controller and PSO-PI controller. The proposed method has fast DC-link voltage response, low THD and good power factor.