You can use an entity selector on the /api/v2/entities endpoint of the Monitored Entities API. For example if you’re looking for hosts with a specific tag:
type(HOST),tag(“[context]key”)
Or, if you’re looking for hosts with a specific tag value:
type(HOST),tag(“[context]key:value”)
context is for specific types of tags like [Environment] or [Azure] and isn’t needed if your tag does not have a context.
The JSON returned will have a “totalCount” which is the number of entities with a tag or tag:value. You can set your pagesize to 1 if all you’re interested in is the total number of entities and not the list of entities.