Webhook verification
Anyone who knows the address of your webhook endpoint could post to it. Each message from ThrustLab carries a signature, and the library can check that signature for you. With it, your server knows a message came from ThrustLab and wasn't changed on the way.
Verify a message
Webhook.verify takes three things: the raw body of the request, the Thrustlab-Signature header, and your endpoint's secret. It returns the event, or raises an error if the message can't be trusted.
import os
from fastapi import FastAPI, HTTPException, Request
from thrustlab import Webhook
from thrustlab.exceptions import SignatureVerificationError
app = FastAPI()
SECRET = os.environ["THRUSTLAB_WEBHOOK_SECRET"]
@app.post("/webhooks/thrustlab")
async def receive(request: Request):
payload = await request.body()
signature = request.headers.get("Thrustlab-Signature", "")
try:
event = Webhook.verify(payload, signature, SECRET)
except SignatureVerificationError as error:
raise HTTPException(status_code=400, detail=str(error))
if event.type == "simulation.completed":
print("finished:", event.data["object"]["id"])
return {"received": True}The secret is the whsec_ value you got when you created the endpoint. See Webhook endpoints.
Pass the raw body
The signature covers the exact bytes ThrustLab sent. Give verify the body as it arrived, as bytes or a string. If your framework has already turned the body into a dictionary and back, the bytes change and the check fails. In FastAPI, read await request.body(), as above.
What can fail
verify raises a SignatureVerificationError in three cases:
- The header is missing or malformed.
- The signature doesn't match. The secret is wrong, or someone changed the body.
- The message is older than 5 minutes. This stops someone from replaying an old message. Pass
tolerance=with a number of seconds to change the limit.
When it raises, answer with a 400 status and do nothing with the message.
Read the event
verify returns an Event with these parts:
| Part | What it holds |
|---|---|
event.id | The id of the event. |
event.type | What happened, such as simulation.completed or simulation.failed. |
event.created | When the event was made, as a UTC time such as 2026-11-18T12:00:00Z. |
event.data | The details. For a run, event.data["object"] is the run as the API returns it. |
event.raw | The whole message as a dictionary. |
Older versions of the library always left event.created at 0. Read event.raw["created_at"] if you use one of them.
Answer quickly and expect repeats
Answer with a status in the 200s within a few seconds, and do the slow work afterward. ThrustLab waits up to 15 seconds for an answer. It doesn't follow redirects, so give the final address.
If your server fails to answer, ThrustLab sends the message again. Your server can then see the same event twice. Keep the event.id of every event you handled, and skip any you have seen. Each delivery also carries a Webhook-Id header with the event id, and a Webhook-Attempt header with the try number.