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:
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.