Light Logo
Webhooks

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 hexgrad/kokoro-82m with a webhook:

from wriftai import Client

# Instantiate the WriftAI client
wriftai = Client()

# Create a prediction using hexgrad/kokoro-82m with a webhook
wriftai.predictions.create(
    model="hexgrad/kokoro-82m",
    input={
        "text": "Good morning! Here is your daily summary.",
    },
    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 using hexgrad/kokoro-82m with a webhook
await wriftai.predictions.create({
    model: 'hexgrad/kokoro-82m',
    input: {
        text: 'Good morning! Here is your daily summary.',
    },
    webhook: {
        url: 'https://example.com/webhooks/wriftai',
        secret: 'top-secret', // This is optional
    },
});
import (
	"context"
	"log"

	"github.com/wriftai/wriftai-go"
)

func main() {
	// Instantiate the WriftAI client
	client := wriftai.NewClient()

	webhookSecret := "top-secret"

	// Create a prediction using hexgrad/kokoro-82m with a webhook
	_, err := client.Predictions.Create(
		context.TODO(),
		wriftai.CreatePredictionParams{
			Model: "hexgrad/kokoro-82m",
			Input: wriftai.PredictionInput{
				"text": "Good morning! Here is your daily summary.",
			},
			Webhook: &wriftai.Webhook{
				URL:    "https://example.com/webhooks/wriftai",
				Secret: &webhookSecret, // This is optional
			},
		},
	)
	if err != nil {
		log.Fatal(err)
	}
}
# Create a prediction using hexgrad/kokoro-82m with a webhook
wriftai predictions create \
   --model hexgrad/kokoro-82m \
   --input 'text=Good morning! Here is your daily summary.' \
   --webhook-url https://example.com/webhooks/wriftai \
   --webhook-secret top-secret
# Create a prediction using hexgrad/kokoro-82m with a webhook
curl "https://api.wrift.ai/v1/predictions" \
  -H "Authorization: Bearer $WRIFTAI_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "hexgrad/kokoro-82m",
    "input": {
      "text": "Good morning! Here is your daily summary."
    },
    "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 2xx status 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 succeeded status may arrive before a webhook for an earlier processing status
  • Webhook delivery logs are only retained for 3 days.

Your webhook handler should be idempotent, and able to safely handle duplicate and out-of-order deliveries.