Yes, wp_is_json_request()
can be used to determine if the current request is a REST API request
Checks whether current request is a JSON request, or is expecting a JSON response.
Official docs: https://developer.wordpress.org/reference/functions/wp_is_json_request/