Python Example
Example of a python request and response for model inference using python's request library
Contents
Python POST Request
Imports
The easiest way to interact with APIs in python is using the requests library.
import requests
import jsonHeaders
Define the 3 headers in a dictionary.
The model specific values can be found 👉 here
URL
Define the url.
https://api.corsali.com/predict/ is the base URL
"fe9e3jpl2-23z8-..." is an example model id
For a list of model ids associated with your organization see 👉 here
JSON
Define your payload data.
This can be done directly in python or as a file passed in. If we define our JSON directly in python we need to convert the data to json using
json.dumps
Post Request
Make a post request by passing in your url, headers, and payload data if it was defined directly in python.
Python Response
Get the response as a JSON object which can then be used as python dictionary. We first check if the query was successful. This is because error messages are strings not JSONs.
Full Code
To run the code below, fill in the organization id, model id, authentication key, and file name.
Last updated
Was this helpful?