Skip to main content

Async REST responses

Instead of waiting for your deployment's response you can have Modelbit call a webhook when the inference completes. This is useful when the service calling Modelbit's REST API cannot synchronously wait for the response due to network or architecture limitations.

The call will respond immediately with the batchId of your inference request and, once the inference completes, it will post the results to the webhook URL you supplied.

Set the response_webhook parameter of modelbit.get_inference:

import modelbit

modelbit.get_inference(..., response_webhook: "https://...")
tip

Use query string parameters in your webhook URL to later identify your request when processing the result in your webhook handler.

Modelbit will retry sending the webhook to your server several times if your server responds with an error (e.g. an HTTP 500).

Ignoring timeouts

The server receiving the webhook should respond quickly. If the response takes longer than 10 seconds Modelbit will treat this as a timeout error and resend the webhook request to your server.

Sometimes it's not possible for your server to respond quickly due to architectural constraints. That's ok! You can tell Modelbit to ignore timeout errors with the response_webhook_ignore_timeout boolean parameter.

Set the response_webhook_ignore_timeout: True parameter of modelbit.get_inference:

import modelbit

modelbit.get_inference(..., response_webhook: "https://...", response_webhook_ignore_timeout: True)