Webhooks

Receive signed events, per conversation or for the organization, verify them, and replay a delivery.

Sparkle sends events as JSON POST requests to URLs you choose, signed so you can check they came from Sparkle. There are three ways to receive them:

UseWhen
A conversation's own webhook_urlA request-scoped integration: whoever starts the conversation handles its events. Pass webhook_url to POST /conversations.
A webhook subscriptionA backend that handles every conversation of the organization. Create one with POST /webhooks, or in the dashboard under Webhooks.
The conversation's event streamA live UI. GET /conversations/{id}/stream sends moment.detected, then conversation.ended after the last moment, as server-sent events: the same events, with the same ids, the webhooks get.

A subscription and a conversation's own webhook are independent: a conversation with a webhook_url in an organization with a subscription sends each of its events to both, one delivery each, with the same event id. Nothing is deduplicated across them.

Test and live

Every subscription belongs to one environment, test or live, and receives only the events of conversations in that environment. A conversation created with a key takes the key's environment (spk_test_… or spk_live_…), one from a connection takes the connection's, and one from a dashboard import takes the environment you pick; the Playground's, and others started in the dashboard, are test.

So trying things out with a test key never sends anything to your production endpoint. A conversation's own webhook_url isn't filtered: it receives that conversation's events whatever the environment.

Set environment when you create the subscription. An API key creates subscriptions in its own environment only: leave environment out and it takes the key's, and naming the other one is refused with validation.webhook.environment_mismatch. In the dashboard, or with a personal access token, you pick either. It can't be changed afterwards: to move an endpoint to the other environment, create a new subscription for it and delete the old one. The dashboard's test inbox subscribes as test.

To subscribe your production endpoint, create it with a live key:

curl -X POST "https://api.sparkle.ai/public/v1/webhooks" \
  -H "X-API-Key: $SPARKLE_LIVE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/webhooks/sparkle", "environment": "live", "events": ["*"]}'

Every event carries livemode: true for a live conversation's events, however it was created, and for pings to a live subscription; false otherwise. Check it when one handler serves both environments.

Events

EventWhen
conversation.createdA conversation was created.
moment.detectedA conversation's moment was detected.
conversation.endedAn ended conversation let go its last moment: no moment.detected for it follows.
conversation.deletedA conversation was deleted, with everything it held.
webhook.pingThe subscription was created, its URL changed, or you called POST /webhooks/{id}/test. Always sent; you can't subscribe to it.

A subscription receives the events it lists in events. "events": ["*"] receives every event, including event types added after the subscription was made; * goes alone, never beside event names. The dashboard subscribes new endpoints this way. A conversation's own webhook receives conversation.created, moment.detected and conversation.ended for that conversation only; its secret and URL are erased when the conversation is deleted, so conversation.deleted goes to subscriptions only.

The API reference documents each event's body under Webhook events.

The event

Every event has the same envelope, as a webhook body and as a stream event's data:

{
  "id": "evt_2jxsy8cc8v0348asy6t1",
  "object": "event",
  "type": "moment.detected",
  "livemode": false,
  "created_at": "2026-12-03T15:04:05Z",
  "data": { "id": "mom_…", "object": "moment", "…": "…" }
}
  • id is the event. It stays the same on every retry and on a replay, and when one event goes to several URLs. Use it to drop repeats.
  • type is the event, which the Sparkle-Event header repeats.
  • livemode is true for a live conversation's events and for a ping to a live subscription (test and live).
  • created_at is when it happened, to the second.
  • data depends on the type:
Eventdata
moment.detectedThe moment, as GET /conversations/{id}/moments lists it.
conversation.createdThe conversation resource, the shape GET /conversations/{id} returns.
conversation.ended{conversation, summary, reason}: the ended conversation; summary with moments_count, moments_by_kind (a count per kind, {} when there were none), duration_s (from started_at to ended_at) and turns_count (final turns); and reason, why it ended: requested, idle, completed or failed (lifecycle).
conversation.deleted{"id": "cnv_…", "object": "conversation", "deleted": true}
webhook.ping{}

A moment looks like this:

{
  "id": "mom_2jxsy8cc8v0348asy6t1",
  "object": "moment",
  "conversation_id": "cnv_2jxsy8cc8v0348asy6t1",
  "kind": "request.do",
  "title": null,
  "text": "Can you send the summary to the board by Friday?",
  "speaker": { "key": "dana", "name": "Dana" },
  "at": 24,
  "confidence": 0.9,
  "turn_ids": ["t5"],
  "settled_ms": 0,
  "classifier": "typesafe:…",
  "definition": null,
  "created_at": "2026-12-03T15:04:05.123456Z"
}

at is seconds from the conversation's started_at, as a turn's start and end are, and turn_ids are the ids you sent the turns with. speaker.name is null when the turn had no name. definition names the custom moment type it was detected as, with the label and color it had then, and is null for a built-in kind. title is always null for now.

Ordering

Sparkle emits a conversation's conversation.ended after its last moment.detected, but each delivery is sent and retried on its own, so they can arrive in any order. Treat a conversation as complete once you hold summary.moments_count of its moments, counted by moment id. The event stream is one ordered stream, so on it conversation.ended always comes after the moments.

Headers

HeaderValue
Sparkle-EventThe event type, such as moment.detected.
Sparkle-DeliveryThe delivery ID, the same on every retry; a replay is a new delivery with its own.
Sparkle-Signaturet=<unix seconds>,v1=<hex HMAC-SHA256>, signed again on each attempt.

Verify the signature

The v1 value is the HMAC-SHA256 of <t>.<raw body>. The key is the signing secret exactly as the API returned it, whsec_ prefix included, as UTF-8 bytes: the subscription's or, for a conversation's own webhook, the webhook.secret its create returned. To verify a delivery:

  1. Read the body as raw text, before any JSON parsing. Re-encoded JSON won't match.
  2. Compute the HMAC of the t value, a ., and the raw body, and compare it with each v1 value in constant time.
  3. Reject the request when t is more than 5 minutes from your clock. This stops a captured request from being replayed later.
verify.ts
import { createHmac, timingSafeEqual } from "node:crypto";

const TOLERANCE_SECONDS = 5 * 60;

export function verifySparkleSignature(
  secret: string,
  header: string,
  rawBody: string,
  nowSeconds = Math.floor(Date.now() / 1000)
): boolean {
  let timestamp = "";
  const signatures: Buffer[] = [];
  for (const part of header.split(",")) {
    const [key, value = ""] = part.trim().split("=");
    if (key === "t") timestamp = value;
    if (key === "v1") signatures.push(Buffer.from(value, "hex"));
  }
  const signedAt = Number(timestamp);
  if (!Number.isInteger(signedAt) || signatures.length === 0) return false;
  if (Math.abs(nowSeconds - signedAt) > TOLERANCE_SECONDS) return false;

  const expected = createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest();
  return signatures.some((sig) => sig.length === expected.length && timingSafeEqual(sig, expected));
}
route.ts
export async function POST(request: Request): Promise<Response> {
  const body = await request.text();
  const signature = request.headers.get("Sparkle-Signature") ?? "";
  if (!verifySparkleSignature(process.env.SPARKLE_WEBHOOK_SECRET!, signature, body)) {
    return new Response("invalid signature", { status: 400 });
  }
  const event = JSON.parse(body);
  // Drop an event.id already handled, handle event.type, then answer 2xx quickly. Do slow work
  // after responding.
  return new Response(null, { status: 204 });
}

Rotate the secret

Rotating a subscription's secret, in the dashboard or with POST /webhooks/{id}/rotate-secret, returns a new secret once. The replaced secret keeps signing beside it for a day, so each delivery then carries two signatures, the new secret's first:

Sparkle-Signature: t=1764763200,v1=<new>,v1=<old>

A receiver that accepts any matching v1, as the sample above and the SDK's verify do, keeps accepting deliveries while you deploy the new secret. Set expires_in to choose the overlap in seconds, up to 604800 (7 days), or 0 to stop the old secret at once, as after a leak. Once the overlap ends, only the new secret signs. The test endpoint signs with the new secret alone.

Retries

Answer with a 2xx within 30 seconds. Sparkle stores up to 10 KB of your response on the delivery.

  • A network error, a timeout, a 429 or a 5xx is retried: up to 5 attempts, the first at once and the next after 1, 2, 4 and 8 minutes.
  • Any other 4xx fails the delivery at once, without retries.
  • A 3xx fails it at once too: redirects aren't followed, so give the URL the endpoint answers on.
  • Each attempt goes to the subscription's URL as it is then, so changing the URL redirects the retries still to come.
  • Sparkle only delivers to addresses on the public internet. A URL naming a private, loopback or link-local address is refused when you create the webhook, and one whose hostname resolves to such an address fails its delivery at once, without retries.

Because an event can arrive more than once, deduplicate on its id.

Deliveries and replay

GET /webhooks/{id}/deliveries lists a subscription's deliveries, newest first. Each delivery shows its status (pending, success, failed, or skipped while the subscription was paused), attempt_count, and the last attempt's http_status and duration_ms. A conversation's own webhook is a subscription too: its id is the conversation's webhook.id, and its deliveries list and replay the same way. It isn't in GET /webhooks, which lists the organization's subscriptions.

To send a delivery again, for example after fixing your endpoint, replay it:

curl -X POST "https://api.sparkle.ai/public/v1/webhooks/$WEBHOOK_ID/deliveries/$DELIVERY_ID/replay" \
  -H "X-API-Key: $SPARKLE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"

The replay is a new delivery with its own Sparkle-Delivery ID and a replay_of field naming the original. It sends the original body, event id included, to the subscription's current URL, even if the subscription is inactive, and is signed and retried like any other delivery. Sending the same Idempotency-Key again returns the first replay and sends nothing.

Failing endpoints

When a subscription's deliveries keep failing, Sparkle warns you, then pauses it so a broken endpoint stops taking retries:

  • A delivery that ends failed marks the endpoint failing, and its failing_since records when; any successful delivery clears it. A failed webhook.ping doesn't count.
  • While it fails, the organization's owners and editors, and the company's owners, get a warning email at most once a day: when a delivery used up its retries, or when the last 5 deliveries all failed. It says when the endpoint will be paused.
  • After 3 days with no successful delivery, the next failure pauses the subscription and they get an email saying so. Its is_active turns false and paused_at records when; failing_since stays as it was.

While paused, the subscription's events are still recorded as deliveries with the status skipped: nothing is sent and no attempt is made, but each keeps its body so you can replay it. A subscription you switch off yourself, with is_active: false, isn't paused: its events aren't recorded for it at all.

In the dashboard, the Webhooks list marks a failing or paused endpoint, and the endpoint's page says when it will be paused, or when it was. Its deliveries can be filtered to the skipped ones.

Re-enable and replay

Fix the endpoint first: send a test event from its page, or call POST /webhooks/{id}/test, until it answers 2xx. Then, on the endpoint's page in the dashboard, choose Re-enable, and then Replay skipped deliveries beside its deliveries. Owners and editors can do both. With the API, re-enable it by setting is_active back to true:

curl -X PUT "https://api.sparkle.ai/public/v1/webhooks/$WEBHOOK_ID" \
  -H "X-API-Key: $SPARKLE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"is_active": true}'

Re-enabling clears paused_at and failing_since, so the 3 days start again from the next failure. The skipped deliveries stay skipped until you replay them with POST /webhooks/{id}/deliveries/replay-skipped. Each call replays up to 500, oldest first, each as a new delivery whose replay_of names the skipped one, and answers {"replayed": 500, "has_more": true}. Call it again while has_more is true; a skipped delivery already replayed is left out, so a call never replays one twice:

curl -X POST "https://api.sparkle.ai/public/v1/webhooks/$WEBHOOK_ID/deliveries/replay-skipped" \
  -H "X-API-Key: $SPARKLE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"

Each call needs its own Idempotency-Key: sending one again returns that call's answer and replays nothing more. Replays are sent even while the subscription is paused, so re-enable it first, or they go to an endpoint that may still be failing.

Every delivery, retried and skipped ones included, is kept for 30 days from its event and then deleted. Replay skipped deliveries within that window: a skipped delivery older than 30 days is gone and can't be sent.

On this page