Skip to main content

Hooks

A hook is an HTTP endpoint that mosaicod sends an event to when data lands: when a topic finishes uploading, and when a session is finalized. Use hooks to run your own code, such as sending a notification or starting a processing job, instead of polling mosaicod.

Registering a hook​

Hooks are managed with the mosaicod hook command:

$ mosaicod hook create http://hooks.internal:8080/
3
$ mosaicod hook ls
ID CREATED URL
3 2026-11-03 11:00 UTC http://hooks.internal:8080/
$ mosaicod hook rm 3

A change applies from the next event on, without restarting mosaicod server.

Events​

Every hook receives every event, as an HTTP POST with a JSON body:

{
"id": "0b6f2c1e-4f1a-4c8e-9a43-2d7e5b1f6a90",
"type": "topic_uploaded",
"data": { … }
}
FieldDescription
idA UUID identifying the event. A retry sends the same event with the same id.
typeThe event type: topic_uploaded or session_uploaded.
dataThe event's fields, which depend on its type.

Timestamps are in Unix nanoseconds. New event types and fields may be added, so a receiver should ignore the ones it doesn't know.

topic_uploaded​

Sent when a topic's upload finishes. The topic's data can't change anymore.

FieldDescription
topicThe topic's locator, sequence/topic.
sequenceThe topic's sequence.
sessionThe session the topic was uploaded in, sequence:session.
ontology_tagThe ontology tag of the topic's data.
user_metadataThe metadata given when the topic was created, or null.
created_atWhen the topic was created.
{
"id": "0b6f2c1e-4f1a-4c8e-9a43-2d7e5b1f6a90",
"type": "topic_uploaded",
"data": {
"topic": "drive_042/front_camera",
"sequence": "drive_042",
"session": "drive_042:01JBX5Q3ZK8V7M2N4P6R8T0W2Y",
"ontology_tag": "image",
"user_metadata": { "driver": "Ada" },
"created_at": 1793707200123456789
}
}

session_uploaded​

Sent when a session is finalized, after all its topics are uploaded.

FieldDescription
sessionThe session's locator, sequence:session.
sequenceThe session's sequence.
topicsThe locators of the session's topics.
created_atWhen the session was created.
{
"id": "6c1d0a52-93e4-4b7f-8d21-5a0e7c3b9f14",
"type": "session_uploaded",
"data": {
"session": "drive_042:01JBX5Q3ZK8V7M2N4P6R8T0W2Y",
"sequence": "drive_042",
"topics": ["drive_042/front_camera", "drive_042/imu"],
"created_at": 1793707200098765432
}
}

An upload or a finalize that fails sends no event.

Delivery​

Delivery is best effort. A request counts as delivered when the hook answers with a 2xx status. Otherwise:

OutcomeWhat mosaicod does
Connection error, no answer within 5 seconds, 429, or 5xxRetries, up to 3 attempts in all, waiting 1 second and then 10 seconds.
Any other statusGives up. Redirects aren't followed.

When it gives up, mosaicod logs a warning with the hook's id, as listed by mosaicod hook ls, the event id and the error.

What that means for a receiver:

  • Answer quickly. Do slow work after answering, or the 5 second timeout makes mosaicod send the event again.
  • An event can be lost. That happens when a hook is down longer than the retries, when mosaicod stops before an event is delivered, and when more than 1024 events are waiting because hooks are slow to answer.
  • An event can arrive twice. If a hook handles a request but its answer doesn't reach mosaicod, the retry sends the same event again, with the same id. Use id to skip duplicates when they matter.
  • Events can arrive out of order. Each mosaicod server sends up to 16 requests to hooks at once.

Security​

warning

Requests to hooks aren't authenticated: anything that can reach a hook can send it fake events. Keep hooks on a network only mosaicod can reach.

Over an http:// URL the request body, user_metadata included, crosses the network in clear. Use https:// when the network between mosaicod and the hook isn't trusted.

Receiving events in Python​

The Python SDK's HookServer receives events and passes each one to your functions. See Hooks in the SDK docs.