Skip to main content
@mynthio/sdk/convex provides mynthWebhookAction() for handling signed Mynth webhooks in Convex HTTP actions.

Webhook helper

import { mynthWebhookAction } from "@mynthio/sdk/convex";

export const mynthWebhook = mynthWebhookAction({
  imageTaskCompleted: async (payload, { context }) => {
    console.log(payload.task.id);
    console.log(payload.result.images);
  },
  imageTaskFailed: async (payload) => {
    console.error("Task failed", payload.task.id);
  },
  imageRateTaskCompleted: async (payload, { context }) => {
    console.log(payload.result.results);
  },
  imageRateTaskFailed: async (payload) => {
    console.error("Rate task failed", payload.task.id);
  },
  imageAltTaskCompleted: async (payload, { context }) => {
    console.log(payload.result.results);
  },
  imageAltTaskFailed: async (payload) => {
    console.error("Alt text task failed", payload.task.id);
  },
});
Each handler maps to a webhook event:
HandlerEvent
imageTaskCompletedtask.image.generate.completed
imageTaskFailedtask.image.generate.failed
imageRateTaskCompletedtask.image.rate.completed
imageRateTaskFailedtask.image.rate.failed
imageAltTaskCompletedtask.image.alt.completed
imageAltTaskFailedtask.image.alt.failed
The helper:
  • verifies the X-Mynth-Signature header using HMAC-SHA256
  • requires the X-Mynth-Event header, then routes on payload.event
  • exposes Convex context (and the original request) for running queries and mutations
If you do not pass webhookSecret explicitly, the helper reads MYNTH_WEBHOOK_SECRET from the environment.

Full walkthrough

For a complete Convex integration including schema, actions, webhooks, and reactive UI, see the Convex full-stack guide.