Set up webhooks
Learn how to set up webhooks on WriftAI
To receive webhook events from WriftAI, include a webhook object when creating a prediction. The webhook object must include a url, and may optionally include a secret. If a secret is provided, WriftAI will sign each webhook request so you can verify its authenticity.
WriftAI will send HTTP POST requests to that webhook URL as the prediction updates. Each webhook request includes a JSON body containing the prediction object, with the same structure returned by
the Get a prediction API.
Here is an example to run deepseek-ai/deepseek-r1 with a webhook:
from wriftai import Client
# Instantiate the WriftAI client
wriftai = Client()
# Create a prediction against deepseek-ai/deepseek-r1 with a webhook
wriftai.predictions.create(
model="deepseek-ai/deepseek-r1",
params={
"input": {
"prompt": "Summarize quantum computing.",
},
"webhook": {
"url": "https://example.com/webhooks/wriftai",
"secret": "top-secret", # This is optional
},
},
)import { WriftAI } from 'wriftai';
// Instantiate the WriftAI client
const wriftai = new WriftAI();
// Create a prediction against deepseek-ai/deepseek-r1 with a webhook
await wriftai.predictions.create({
model: 'deepseek-ai/deepseek-r1',
input: {
prompt: 'Summarize quantum computing.',
},
webhook: {
url: 'https://example.com/webhooks/wriftai',
secret: 'top-secret', // This is optional
},
});import (
"context"
"encoding/json"
"log"
"github.com/wriftai/wriftai-go"
)
func main() {
// Instantiate the WriftAI client
client := wriftai.NewClient()
webhookSecret := "top-secret"
// Create a prediction against deepseek-ai/deepseek-r1 with a webhook
_, err := client.Predictions.Create(
context.TODO(),
"deepseek-ai/deepseek-r1",
wriftai.CreatePredictionParams{
Input: json.RawMessage(`{"prompt":"Summarize quantum computing."}`),
Webhook: &wriftai.Webhook{
URL: "https://example.com/webhooks/wriftai",
Secret: &webhookSecret, // This is optional
},
},
false, // do not wait for completion
nil,
)
if err != nil {
log.Fatal(err)
}
}# Create a prediction against deepseek-ai/deepseek-r1 with a webhook
wriftai predictions create \
--model deepseek-ai/deepseek-r1 \
--input '{"prompt": "Summarize quantum computing."}' \
--webhook-url https://example.com/webhooks/wriftai \
--webhook-secret top-secret# Create a prediction against deepseek-ai/deepseek-r1 with a webhook
curl -s -X POST "https://api.wrift.ai/v1/models/deepseek-ai/deepseek-r1/predictions" \
-H "Authorization: Bearer $WRIFTAI_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"input": {
"prompt": "Summarize quantum computing in one simple sentence."
},
"webhook": {
"url": "https://example.com/webhooks/wriftai",
"secret": "top-secret"
}
}'Track deliveries
You can view webhook delivery attempts, response status codes, and errors on the Webhooks page in your dashboard. This is useful for debugging failed or delayed webhook deliveries.
Requirements and guarantees
When setting up webhook handlers, keep the following in mind:
- Your webhook URL must be publicly accessible over HTTPS (for local development, you can use a tool like ngrok)
- Your endpoint should respond with a
2xxstatus code as quickly as possible - Webhook events may be delivered more than once
- Delivery order is not guaranteed — in rare cases, a webhook for a prediction with a
succeededstatus may arrive before a webhook for an earlierprocessingstatus
Your webhook handler should be idempotent, and able to safely handle duplicate and out-of-order deliveries.