Lifecycle webhooks
Use lifecycle webhooks when another system must react to memory changes without polling. SPM sends signed HTTP events for accepted, duplicate, purge, refusal, partition, and import outcomes. Deliveries include a stable event ID, so your receiver can verify the message and safely ignore duplicates.
Subscribe
The event API uses the audit scope. Register a destination with POST /v2/events/subscriptions:
curl https://api.spmos.ai/v2/events/subscriptions \
-H "Authorization: Bearer $SPM_API_KEY" \
-H 'Content-Type: application/json' \
-d "{\"url\":\"$WEBHOOK_URL\",\"events\":[\"source.accepted\",\"source.purged\"]}"
SPM returns a subscription ID, the selected event names, and a generated secret. Save the secret when you create the subscription. Listing subscriptions returns it again, so a lost secret is recoverable, but anyone holding the audit scope can read it too. The request URL must be 8 to 512 characters. The event list must contain at least one name and may contain at most 16 names.
You can list subscriptions with GET /v2/events/subscriptions. Delete one with DELETE /v2/events/subscriptions/{id}. Both operations require the audit scope. SPM allows up to 32 subscribers. It rejects unknown event names instead of silently ignoring them.
Event types
Subscribe only to the events your receiver needs:
source.accepted: SPM accepted a source.source.duplicate: SPM received a duplicate source.source.purged: SPM removed a source.recall.refused: recall could not support the request.partition.wiped: SPM wiped a partition.memory.imported: SPM imported memory.
The event body is JSON. It includes an event ID, event type, creation time, and event-specific payload. The event type also appears in X-SPM-Event. Do not use the type alone for deduplication. Use the event ID.
Verify each delivery
SPM sends these headers:
X-SPM-Event-Id: the stable event ID.X-SPM-Signature:t=<unix>,v1=<hex HMAC>.
To verify a request, parse the timestamp and signature. Recompute HMAC-SHA256 over the bytes timestamp + "." + raw_request_body, using the subscription secret. Compare the result with v1 using a constant-time comparison. Verify the timestamp against your replay window before processing the body. Keep the raw body unchanged until verification finishes.
A receiver must deduplicate by event ID. Delivery is at least once. SPM retries failed delivery after 0.5, 2, and 5 seconds. It treats a response below 500, except 429, as delivered. It records a failed delivery after the retry sequence ends. Return a successful status only after you have durably recorded the event or can safely process it again.
A minimal receiver follows this order:
receive raw body and headers
parse t and v1 from X-SPM-Signature
reject an old timestamp
verify HMAC(secret, t + "." + raw body)
if event_id was already handled: return 2xx
store event_id and body
process the event
return 2xx
Replay events
SPM keeps published events in a file-backed outbox. After a receiver outage, call POST /v2/events/replay with the audit scope. Pass {"since_id":"evt_..."} to re-deliver events after a known event ID. Pass an empty object to re-deliver all outbox events. The response reports how many deliveries SPM queued. Replay follows each subscription's event filter and uses the normal signatures and retry behavior.
Limits
This service runs in one API process and uses a local outbox and delivery thread pool. It is not a broker or a cross-replica event log. The outbox lets a restart retain events, but it does not remove the need for receiver deduplication. SPM does not guarantee exactly-once delivery or event ordering across subscribers. A subscription secret is returned in the subscription response, so store it securely and delete the subscription if you lose it. The API rejects more than 32 subscribers. Check the response from replay and your receiver logs before treating recovery as complete.