puter.workers.exec()Sends a request to a worker endpoint while automatically passing the user's session.
fetch(), puter.workers.exec() automatically includes the user's session. This provides the worker with the user context (user.puter), enabling the User-Pays model.
puter.workers.exec(workerURL, options)
workerURL (String)(Required)
The URL of the worker to execute.
options (Object)
A standard RequestInit object
A Promise that resolves to a Response object (similar to the Fetch API).
Execute a worker
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
// Execute a worker and get the response
const response = await puter.workers.exec('https://my-worker.puter.work');
const data = await response.text();
puter.print(`Response: ${data}`);
})();
</script>
</body>
</html>