Webhooks
Webhooks work in tandem with the queue system explained above, it is another way to interact with our queue. By providing us a webhook endpoint you get notified when the request is done as opposed to polling it.
Here is how this works in practice, it is very similar to submitting something to the queue but we require you to pass an extra fal_webhook
query parameter.
To utilize webhooks, your requests should be directed to the queue.fal.run
endpoint, instead of the standard fal.run
. This distinction is crucial for enabling webhook functionality, as it ensures your request is handled by the queue system designed to support asynchronous operations and notifications.
The request will be queued and you will get a response with the request_id
and gateway_request_id
:
These two will be mostly the same, but if the request failed and was retried, gateway_request_id
will have the value of the last tried request, while
request_id
will be the value used in the queue API.
Once the request is done processing in the queue, a POST
request is made to the webhook URL, passing the request info and the resulting payload
. The status
indicates whether the request was successful or not.
Successful result
The following is an example of a successful request:
Response errors
When an error happens, the status
will be ERROR
. The error
property will contain a message and the payload
will provide the error details. For example, if you forget to pass the required model_name
parameter, you will get the following response:
Payload errors
For the webhook to include the payload, it must be valid JSON. So if there is an error serializing it, payload
is set to null
and a payload_error
will include details about the error.