In order not to get confused by different stats reported, make sure you are using the same parameters, modes and targets for your queries:

API:

http://apiv2.ahrefs.com/?token=XXX&target=ahrefs.com&limit=1000&output=json&from=metrics_extended&mode=subdomains 

Site Explorer:

https://ahrefs.com/site-explorer/overview/v2/subdomains/live?target=ahrefs.com

In above examples I analysed target ahrefs.com in 'subdomains' mode and got the same numbers for both requests.

Moreover, it is worth mentioning that API data is currently available for Live index only, so consider that when comparing results as well.

Did this answer your question?