API node user API

Predictions are obtained on the API node by using the User REST API.

The REST API

Request and response formats

For POST and PUT requests, the request body must be JSON, with the Content-Type header set to application/json.

For almost all requests, the response will be JSON.

Whether a request succeeded is indicated by the HTTP status code. A 2xx status code indicates success, whereas a 4xx or 5xx status code indicates failure. When a request fails, the response body is still JSON and contains additional information about the error.

Authentication

Each service declares whether it uses authentication or not. If the service requires authentication, the valid API keys are defined in DSS.

The API key must be sent using HTTP Basic Authorization:

  • Use the API key as username
  • The password can remain blank

The valid API keys are defined on the DSS side, not on the API node side. This ensures that all instances of an API node will accept the same set of client keys

Methods reference

The reference documentation of the API is available at https://doc.dataiku.com/dss/api/4.0/apinode-user

API Python client

Dataiku provides a Python client for the API Node user API. The client makes it easy to write client programs for the API in Python.

Installing

  • The API client is already pre-installed in the DSS virtualenv
  • From outside of DSS, you can install the Python client by running pip install dataiku-api-client

Reference API doc

class dataikuapi.APINodeClient(uri, service_id, api_key=None)

Entry point for the DSS API Node client This is an API client for the user-facing API of DSS API Node server (user facing API)

predict_record(endpoint_id, features, forced_generation=None, dispatch_key=None, context=None)

Predicts a single record on a DSS API node endpoint (standard or custom prediction)

Parameters:
  • endpoint_id (str) – Identifier of the endpoint to query
  • features – Python dictionary of features of the record
  • forced_generation – See documentation about multi-version prediction
  • dispatch_key – See documentation about multi-version prediction
  • context – Optional, Python dictionary of additional context information. The context information is logged, but not directly used.
Returns:

a Python dict of the API answer. The answer contains a “result” key (itself a dict)

predict_records(endpoint_id, records, forced_generation=None, dispatch_key=None)

Predicts a batch of records on a DSS API node endpoint (standard or custom prediction)

Parameters:
  • endpoint_id (str) – Identifier of the endpoint to query
  • records – Python list of records. Each record must be a Python dict. Each record must contain a “features” dict (see predict_record) and optionally a “context” dict.
  • forced_generation – See documentation about multi-version prediction
  • dispatch_key – See documentation about multi-version prediction
Returns:

a Python dict of the API answer. The answer contains a “results” key (which is an array of result objects)