Avoiding initial load for image transform
You can tell Craft to generate new image transforms right when getUrl() is called by setting the generateTransformsBeforePageLoad config setting to true. Assuming you still want the default behavior on your main website, you can set the setting programatically from your endpoint config with ConfigService::set():

'endpoint/path' =&gt; function() {
    craft()-&gt;config-&gt;set('generateTransformsBeforePageLoad', true);

    return [
        // ...
    ];
},