API input
The payload parameter type in predict(self, payload) can vary based on the content type of the request and can be parsed according to the Content-Type header in the request. The parsing rules are as follows:
For header Content-Type: application/json, thepayload parameter will be the parsed JSON body.
For Content-Type: multipart/form-data / Content-Type: application/x-www-form-urlencoded, payload will be starlette.datastructures.FormData (key-value pairs where the values are strings for text data, or starlette.datastructures.UploadFile for file uploads; see Starlette's documentation).
For all other Content-Type values, payload will be the raw bytes of the request body.

JSON data

Request

$ curl https://***.syndic.ai \
-X POST \
-H "Content-Type: application/json" \
-d '{"key": "value"}'

Inside Model

class PythonPredictor:
def __init__(self, config):
pass
def predict(self, payload):
print(payload["key"]) # prints "value"

Sample models

Form data

Sample request

$ curl https://***.c1.syndic.ai \
-X POST \

Inside Model

from PIL import Image
import pickle
class PythonPredictor:
def __init__(self, config):
pass
def predict(self, payload):
text = payload["text"].file.read()
print(text.decode("utf-8")) # prints the contents of text.txt
obj = pickle.load(payload["object"].file)
print(obj["key"]) # prints "value" assuming `object.pkl` is a pickled dictionary {"key": "value"}
img = Image.open(payload["image"].file)
print(img.size) # prints the dimensions of image.png

Sample models

Copy link
On this page
JSON data
Form data