You need to wrap the setData function inside the on("tableBuilt") callback to ensure that the table is fully initialized before loading the data.
// Trigger AJAX data load on table built event
table.on("tableBuilt", async () => {
table.setData("/api/...");
});