Electronic structure calculations of KBe2BO3F2 crystal from first principles have been performed based on a plane-wave pseudopotential method for the first time. Its optical linear and second harmonic generation (SHG) coefficients are also calculated. The SHG coefficient measured early was much higher than that of our calculation, however, recent experiment confirms our calculated results. Moreover, a real-space atom-cutting method is adopted to analyze the respective contributions of the cation and anionic group to optical response. The results show that the contributions to the SHG coefficients from the (BO3)3− and (BeFO3)5− groups are dominant and comparable.