Skip to main content
If you supply a callback_url argument to your function decorator, Beam will make a POST request to your server whenever a task finishes running. Callbacks fire for both successful and failed tasks. Callbacks include the Beam Task ID in the request headers, and the task response URL-encoded in the request body.
For testing purposes, you can setup a temporary webhook URL using https://webhook.site

Registering a Callback URL

Callbacks can be added onto endpoints, functions, and task queues:

Callback format

Data Payload

The callback will send the response from your function as JSON, in the data field:

Request headers

The request headers include the following fields:
  • x-task-timestamp — timestamp the task was created.
  • x-task-signature — signature to verify that the request was sent from Beam.
  • x-task-status — status of the task.
  • x-task-id — the task ID.

Request Level Callbacks

There are cases where you might want to define a different callback_url for each request, for example if you have different environments for staging and prod. You can pass callback_url as a payload to anything you’re running on Beam, and we’ll use that as the callback for the request:
When using request-level callbacks, you must include either the callback_url value or kwargs (**inputs) as input to the handler function:

Verifying Requests

Timestamp Verification

To secure your server against replay attacks, a timestamp and signature are included in the callback request headers. As a best-practice, it is wise to check the timestamp header of each callback request. If the timestamp is over 5s old, there is a risk that the callback was not fired from Beam.

Signature Verification

The most secure way of verifying a callback request is through signature verification. Your Signature Token can be found in the dashboard, on the Settings -> General page.

Validating a Signature

The callback request will include a header field called x-task-signature. x-task-signature is a unique signature generated by converting the request body to base64, concatenating it with the timestamp, and signing it with your Beam signature token. The code below shows how to validate a callback signature: