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 json

Headers

Define the 3 headers in a dictionary.

The model specific values can be found 👉 here

URL

Define the url.

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

If your payload is defined directly in python make sure to use python syntax (ie JSON uses "true" but python uses "True")

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?