Skip to main content

Single inference REST requests

The easiest way to fetch inferences from a deployment is one at a time. The single inference syntax is suited for use cases where you want predictions about one customer or event at a time.

To retrieve one inference at a time use this single inference syntax.

Request format

Calling a deployment with a single inference request involves sending POST request with the arguments for the deployment's main function.

For example, suppose the deployment's main function is example_doubler:

def example_doubler(foo: int):
return 2 * foo

And example POST data for this deployment to double the number 10 is:

{ "data": 10 }

Using curl

Calling example_doubler with curl:

curl -s -XPOST "https://<your-workspace-url>/v1/example_doubler/latest" \
-d '{"data": 10}'

Using Python

Calling example_doubler with modelbit.get_inference:

import modelbit

modelbit.get_inference(deployment="example_doubler", workspace="your_workspace", data=10)

Calling example_doubler with the requests package:

import json, requests"https://<your-workspace-url>/v1/example_doubler/latest",
data=json.dumps({"data": 10})).json()

Response format

The REST response for deployments called for a single inference is a data field with the return value of the main function.

The response from example_doubler called above with the number 10 is:

{ "data": 20 }

More examples

Here are a few more examples of how to call deployments with single inference requests.

Dictionary arguments

If your deployment expects a single dictionary you can send that as the value of the data parameter.

For example, the following example_dict_doubler expects a dictionary of the form {"value": <number>}:

def example_dict_doubler(d: dict):
return d["value"] * 2

Call example_dict_doubler by sending {"value": 10} as the data:

curl -s -XPOST "https://<your-workspace-url>/v1/example_dict_doubler/latest" \
-d '{"data": {"value": 10}}'

Multiple arguments

If your deployment expects multiple arguments you can send them as an array.

For example, the following example_adder expects three numeric inputs, [a, b, c]:

def example_adder(a: int, b: int, c: int):
return a + b + c

Call example_adder by sending [3, 4, 5] as the data:

curl -s -XPOST "https://<your-workspace-url>/v1/example_adder/latest" \
-d '{"data": [3, 4, 5]}'