Using the REST API from javascript in custom module

I’m developing some functions in a module for the company which are very specific. Is there a way to use the REST API inside a page without putting a hardcoded API key inside the php file? I mean something like a temporary API key which can be generated in the php file with the same permissions as the user loading the page.