Skip to main content

Single inference REST requests

The single inference syntax is suited for use cases where you want predictions about one customer or event per API call.

tip

Example syntax for calling each of your deployments can be found in the API Endpoints tab in Modelbit.

Making requests

Suppose our deployment's main function is example_doubler:

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

In this example we'll double the number 10 with example_doubler:

Calling example_doubler with modelbit.get_inference:

import modelbit

modelbit.get_inference(
deployment="example_doubler",
workspace="<YOUR_WORKSPACE>",
region="<YOUR_REGION>",
data=10)

# return value
{"data": 20 }

The response is the return value of the inference function.

Request format

For functions with a single argument like in the example above, the request format is just that argument. If your function has multiple arguments, send them in a list. Here are some examples calling functions expecting different kinds of arguments:

Dictionary arguments

This deployment expects a dictionary:

def my_deployment(d: Dict[str, float]):
...

To send {"my_key": 25} as the input, send the dictionary as the data parameter:

import modelbit

modelbit.get_inference(..., data={"my_key": 25})

Multiple arguments

This deployment expects several arguments:

def my_deployment(a: int, b: str, c: float):
...

To send 1, "two", 3.0 as the input, send them as a list in the data parameter:

import modelbit

modelbit.get_inference(..., data=[1, "two", 3.0])

List arguments

If your deployment expects a list of values as a single input, you'll need to use the batch syntax to differentiate this request from the earlier example. This syntax is a bit more complicated.

tip

To simplify your function's API format, change your function to accept a dictionary instead of a list. Then send a dictionary where one key is the list of values to use with your model.

This deployment expects a list of numbers:

def my_deployment(my_list: List[int]):
...

To send [1, 2, 3] using batch syntax we'll next this single-inference in a list-of-lists, with an ID. We'll use 0 as the ID for this input (it can be any value).

import modelbit

my_list = [1, 2, 3]
modelbit.get_inference(..., data=[[0, my_list]])