Concepts

Delivery

How events reach you, by stream or webhook, and how to handle retries, replays and repeats.

Every moment goes out as a moment.detected event. You can receive it three ways, and use more than one at once:

UseWhenHow
The conversation's event streamA live UI, or a worker that follows one conversation.GET /conversations/{id}/stream, server-sent events.
The conversation's own webhookWhoever starts the conversation handles its events.Pass webhook_url when you create it.
A webhook subscriptionOne backend handles every conversation of the organization.POST /webhooks, or Webhooks in the dashboard.

The stream carries moment.detected only. Webhooks also get the conversation's lifecycle:

EventWhen
conversation.createdA conversation was created.
moment.detectedA moment was let go.
conversation.endedAn ended conversation let go its last moment. data.summary counts what it produced.
conversation.deletedA conversation was deleted, with everything it held. Subscriptions only.

The event

The same envelope travels on every path:

{
  "id": "evt_2kd7qd8k2p6t0x4a7c1f",
  "object": "event",
  "type": "moment.detected",
  "livemode": false,
  "created_at": "2026-12-03T15:00:31Z",
  "data": {
    "id": "mom_2kd7qb3f7j1n5r9v2y6d",
    "object": "moment",
    "kind": "request.do",
    "text": "I'll get the SSO fix out by Friday.",
    "…": "…"
  }
}

The event id is the one to deduplicate on. It's the same on the stream and in the webhook, on every retry and replay, and when one event goes to several URLs. Store the IDs you've handled and skip one you've seen.

The stream

The stream sends the moments already let go first, then each new one as it's let go, until you disconnect:

: connected

id: 1796310031377-0
event: moment.detected
data: {"id":"evt_2kd7qd8k2p6t0x4a7c1f","object":"event","type":"moment.detected","livemode":false,"data":{…}}

: heartbeat
  • Lines starting with : are comments that keep the connection open. Ignore them.
  • Each event's id: line is its position in the stream, not the event ID. To resume after a dropped connection, send the last one back in the Last-Event-ID header and the stream continues after it. Browser EventSource does this for you.
  • The stream needs your API key, so open it from your server, never from a browser, and relay what your UI needs.

@sparkle/sdk is in private beta

The TypeScript tabs use @sparkle/sdk, which isn't on npm yet. To try it, ask us for access. Python and Go have no SDK yet: the cURL, Python and Go tabs call the HTTP API directly.

curl -N https://api.sparkle.ai/public/v1/conversations/$CONVERSATION_ID/stream \
  -H "X-API-Key: $SPARKLE_API_KEY" \
  -H "Last-Event-ID: 1796310031204-0"

Webhooks

Each delivery is a POST with the event as its body and three headers: Sparkle-Event (the type), Sparkle-Delivery (the delivery, the same on every retry) and Sparkle-Signature. Check the signature before you trust the body: Verify the signature has the code.

  • Answer 2xx within 30 seconds. Do slow work after you answer.
  • Retries. 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.
  • Replay. POST /webhooks/{id}/deliveries/{deliveryId}/replay sends a delivery again, for example after you fix your endpoint. The replay carries the same event id.
  • Order. Each delivery is sent and retried on its own, so events can arrive out of order. conversation.ended is emitted after a conversation's last moment; treat the conversation as complete once you hold summary.moments_count of its moments.

A conversation's own webhook and a subscription are independent. When both exist, each event goes to both, with the same event id. Webhooks covers subscriptions, secrets, deliveries and replay in full.

Catching up

If you missed events, GET /conversations/{id}/moments lists a conversation's moments in the order they were let go. Each one has the moment id that was inside its event's data.

Safe retries on your side

Every POST and PUT you send needs an Idempotency-Key header, such as a UUID. Sending the same key again returns the first request's response and does nothing twice, so when a request times out, retry it with the same key. Use a new key for each new request. A retry that arrives while the first is still running gets 409 conflict.idempotency_key: wait, then send it again.

On this page