> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mynth.io/llms.txt
> Use this file to discover all available pages before exploring further.

# TanStack Start

> Verify and route Mynth webhooks in TanStack Start server routes.

`@mynthio/sdk/tanstack-start` provides `mynthWebhookHandler()` for handling signed Mynth webhooks in TanStack Start server routes.

```ts theme={"theme":"kanagawa-dragon"}
// src/routes/api/webhooks/mynth.ts
import { mynthWebhookHandler } from "@mynthio/sdk/tanstack-start";
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/api/webhooks/mynth")({
  server: {
    handlers: {
      POST: mynthWebhookHandler({
        imageTaskCompleted: async (payload, { request, params, context }) => {
          console.log("Completed task", payload.task.id);
          console.log("Received at", request.url);

          await saveImages(payload.task.id, payload.result.images);
        },
        imageTaskFailed: async (payload) => {
          await markTaskFailed(payload.task.id, payload.errors);
        },
      }),
    },
  },
});
```

Set the signing secret shown when you create the webhook:

```env theme={"theme":"kanagawa-dragon"}
MYNTH_WEBHOOK_SECRET=wbs_...
```

The helper reads the raw request body, verifies `X-Mynth-Signature`, checks `X-Mynth-Event`, and calls the matching typed handler. Each handler also receives the original unread TanStack Start `request`, route `params`, and middleware `context`.

Keep the server route publicly reachable. Make callback side effects idempotent, and enqueue slow work before returning. Callback errors are propagated so Mynth can retry the delivery.

Pass `{ webhookSecret: "wbs_..." }` as the second argument when the application does not use `MYNTH_WEBHOOK_SECRET`. The helper accepts signed dashboard-managed webhooks; request-level custom webhooks are not signed.
