Probably better as a library or middleware. Remote API would likely incur too much latency
The downside of having a local library, would be that the actual user agents db and any data used to generate the results would be stored locally.
I would say that providing a fast, cloud based API, would simplify the developer experience.
This is for something that really doesn't change that much and is sufficiently narrow in possibilities that a library makes a lot of sense. I believe they already exist.
Think about how an API service like this relates to GDPR.