Making Predictions
Promote API
Promote provides an API for querying predictive models. Querying a model consists of sending in structured data to the model, allowing the model to process the data and make a prediction, then returing that prediction from the model to the requesting client.
Making a prediction on Promote is done via an REST API POST request containing a single piece of data for processing.
The remainder of this document will cover some commonly asked questions about the API.
Each deployment of a new model receives its own endpoint. This endpoint can be queries via an HTTP request. Endpoints follow the pattern:
https://promote.yourcompany.com/<user_name>/models/<model_name>/predict
https://promote.yourcompany.com/kermit/models/HelloWorld/predict
- User: kermit
- Model: HelloWorld
When a new version of a model is deployed, the new model is read into memory and, once it's online and ready to process predictions, it will be "hot-swapped" into the endpoint. This means there is zero downtime between deployments.
Promote uses Basic Auth for authenticating predictions, or API requests. To authenticate with Basic Auth, provide an HTTP header with:
- name "Authorization"
- value "Basic "
- your base64 encoded apikey
Authorization: Basic a2VybWl0OmFiY2QxMjM0NTY3ODk=
curl -vX POST -H "Content-Type: application/json" \
--user kermit:abcd123456789 \
--data '{"name":"hank"}' \
https://promotesandbox.alteryx.com/kermit/models/HelloWorld/
* Trying 52.5.5.183...
* Connected to promotesandbox.alteryx.com (52.5.5.183) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.alteryx.com
* Server certificate: COMODO RSA Domain Validation Secure Server CA
* Server certificate: COMODO RSA Certification Authority
* Server certificate: AddTrust External CA Root
* Server auth using Basic with user 'kermit'
> POST /kermit/models/HelloWorld/ HTTP/1.1
> Host: promotesandbox.alteryx.com
> Authorization: Basic a2VybWl0OmFiY2QxMjM0NTY3ODk=
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 15
Most HTTP libraries should have a standard way of making a Basic Auth request. For example, in Ruby it would look like this:
require 'net/http'
require 'uri'
require 'json'
url = URI('https://promotesandbox.alteryx.com/kermit/models/HelloWorld/')
# Create new request
req = Net::HTTP::Post.new(url.path)
# Encode basic auth
req.basic_auth "kermit", "abcd123456789"
The Promote model endpoint accepts JSON as a data format. Typically you'll be working with standard JSON.
Standard JSON
Using the JSON format, Promote will serialize the data and feed it directly into the model that you're calling.
Python models
For Python models, data is serialized using the json.dumps function from the built-in json library. This means your data will end up in the model as either a Python list or a Python dictionary data-type.
R models
For R models, data is serialized using the jsonlite::toJSON function. Serialization is convenient and powerful when performing complex analysis and linear algebra. As a result of the vectorization, vectorized JSON data may be returned from models. For example:
{
"result": {
"name": ["Hello Kermit!"]
},
"promote_id": "c747df0729df439fac632e45146c5993"
}
REST API
Models deployed to Promote can be queried using a standard REST API post request.
The Python code snippets below demonstrate how this can be done:
https://<PROMOTE_URL>/<username>/models/<name>/predict
Make a prediction using <username> and the models <name>.
- HTTP headers
- username: Your username (e.g. kermit, kermit@themuppets.com)
- name: The name of your deployed model (e.g. HelloWorld)
- data: Data required to make a prediction. This is sent in the request body as JSON (e.g. {"name": "Kermit"})
import requests
data = '''{"name":"hank"}'''
#Post request body with basic auth
r = requests.post('https://promotesandbox.alteryx.com/kermit/models/HelloWorld/predict', data=data, auth=('kermit', 'abcd123456789'))
#Print response
print(r.text)
# {"result":{"greeting":"Hello hank!"},
# "version":5,
# "promote_id":"20df311a254c2c08d6e04af0da941312",
# "promote_model":"HelloWorld"}