Remote get featured image from external REST API and add it via .php file

Okay, perhaps the question sounds a bit complicated, but here we go:

I have a single.php file where I get a lot of data from an external API. This works perfectly and I even can get the path to the image I want to set as the featured image for my posts, however: I do not know if and how it is possible to set this featured image with this URL within single.php.

Like, doing:

$response = wp_remote_get( "[path][to][featuredimg]"

I know that there are plugins out there, but is there a way to automate this process within my single.php to create the featured image automatically within that file?

Any help/suggestions?