You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Webhooks provide real-time updates about your prediction. Specify an endpoint when you create a prediction, and Replicate will send HTTP POST requests to that URL when the prediction is created, updated, and finished.
95
+
96
+
It is possible to provide a URL to the predictions.create() function that will be requested by Replicate when the prediction status changes. This is an alternative to polling.
97
+
98
+
To receive webhooks you’ll need a web server. The following example uses Hono, a web standards based server, but this pattern applies to most frameworks.
99
+
100
+
<details>
101
+
<summary>See example</summary>
102
+
103
+
```js
104
+
import { serve } from'@hono/node-server';
105
+
import { Hono } from'hono';
106
+
107
+
constapp=newHono();
108
+
app.get('/webhooks/replicate', async (c) => {
109
+
// Get the prediction from the request.
110
+
constprediction=awaitc.req.json();
111
+
console.log(prediction);
112
+
//=> {"id": "xyz", "status": "successful", ... }
113
+
114
+
// Acknowledge the webhook.
115
+
c.status(200);
116
+
c.json({ok:true});
117
+
}));
118
+
119
+
serve(app, (info) => {
120
+
console.log(`Listening on http://localhost:${info.port}`)
121
+
//=> Listening on http://localhost:3000
122
+
});
123
+
```
124
+
125
+
</details>
126
+
127
+
Create the prediction passing in the webhook URL to `webhook` and specify which events you want to receive in `webhook_events_filter` out of "start", "output", ”logs” and "completed":
0 commit comments