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.
- modelbit.get_inference
- requests
- curl
Set the response_webhook
parameter of modelbit.get_inference
:
import modelbit
modelbit.get_inference(..., response_webhook: "https://...")
Add "response_webhook": "<YOUR_URL>"
as a sibling to your data
:
import json, requests
requests.post("https://...",
data=json.dumps({
"data": ...,
"response_webhook": "https://..."
})).json()
The body posted to the webhook is in the same format as when the REST API is called synchronously. The response header x-mb-batch-id
contains the batchId
of the request.
Add "response_webhook": "<YOUR_URL>"
as a sibling to your data
:
curl -s -XPOST "https://..." -d '{"data": ..., "response_webhook": "https://..."}'
The body posted to the webhook is in the same format as when the REST API is called synchronously. The response header x-mb-batch-id
contains the batchId
of the request.
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.
- modelbit.get_inference
- requests
- curl
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)
Add "response_webhook_ignore_timeout": True
as a sibling to response_webhook
:
import json, requests
requests.post("https://...",
data=json.dumps({
"data": ...,
"response_webhook": "https://...",
"response_webhook_ignore_timeout": True
})).json()
Add "response_webhook_ignore_timeout": true
as a sibling to response_webhook
:
curl -s -XPOST "https://..." \
-d '{"data": ..., "response_webhook": "https://...", "response_webhook_ignore_timeout": true}'