When we released our Replicate integration last month, we added support for tasks that could be completed via a one-time webhook request to support Replicate Prediction webhooks. Replicate webhooks work by providing a URL for a "callback" request when creating a prediction:


await replicate.predictions.create({
version: "d55b9f2d...",
input: { prompt: "call me later maybe" },
webhook: "https://example.com/replicate-webhook",
webhook_events_filter: ["completed"], // optional
});

This allowed us to create an integration task that uses these webhooks to provide a seemless experience when creating a prediction:


const prediction = await io.replicate.predictions.createAndAwait(
"create-prediction",
{
version: "d55b9f2d...",
input: {
prompt: "call me later maybe",
},
}
);

We've now nicely exposed the same functionality so anyone can take advantage of similar APIs with our new io.waitForRequest() built-in task. This task allows you to create a task that will wait for a request to be made to a specific URL, and then return the request body as the task result. This is useful for any API that requires a webhook to be set up, or for any API that requires a callback URL to be provided.

For example, you could use it to interface with ScreenshotOne.com to take a screenshot of a website and resume execution once the screenshot is ready:


const result = await io.waitForRequest(
"screenshot-one",
async (url) => {
await fetch(`https://api.screenshotone.com/take`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
access_key: process.env.SCREENSHOT_ONE_API_KEY,
url: "https://trigger.dev",
store: "true",
storage_path: "my-screeshots",
response_type: "json",
async: "true",
webhook_url: url, // this is the URL that will be called when the screenshot is ready
storage_return_location: "true",
}),
});
},
{
timeoutInSeconds: 300, // wait up to 5 minutes for the screenshot to be ready
}
);

How to update

The trigger.dev/* packages are now at v2.2.6. You can update using the following command:


npx @trigger.dev/cli@latest update

Ready to start building?

Build and deploy your first task in 3 minutes.

Get started now