Yes, you are correct, the in5 API specifically runs within the Adobe ExtendScript engine.
The #targetengine 'in5api' directive is the key that hooks your script into this environment, ensuring that your commands are executed.
There is currently no supported way to use the in5 scripting API in a UXP-based script using require() or import. You’ll need to use ExtendScript for now if you want access to that API, which will allow you to automate in5 workflows.