Hi Chenrui,
You cannot aggregate the result of the Search Query Performance Report and compare it with the result with the AdGroup Performance Report. This is because the metrics from the AdGroup Performance Report are triggered from different criteria types. It does not mean that the metrics from your ad groups in the AdGroup Performance Report comes from your search terms only. It is also possible that your ads under your ad groups were triggered by the actual keywords, location, search terms and other targeting criteria. So this is already an accumulated statistics from different targeting criteria. Just on this scenario alone, you cannot compare the returned values of both report types.
Also, since API only mirrors the AdWords UI, then both have the same values at the same time. However, if you can observe the discrepancies between the AdWords UI and API reports, then just let me know so I can further check.