This works: ("Pirin" is just a random page with some broken links)
https://en.wikipedia.org/w/api.php?action=query&format=json&titles=P...
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&format=jso...
This gives you a list of all links on a page; you need to parse the JSON data and count how many entries have `"missing": true`.
Note that if there are more than 500 links on a page, you'll need to continue the query to get the full list (https://www.mediawiki.org/wiki/API:Query#Continuing_queries). It seems that conveniently all the broken links are listed first, but I'm not sure if this can be relied on.