Skip to content

On-premise users: click in-app to access the full platform documentation for your version of DataRobot.

Prediction API snippets

DataRobot provides sample Python code containing the commands and identifiers required to submit a CSV or JSON file for scoring. You can use this code with the DataRobot Prediction API. To use the Prediction API Scripting Code, open the deployment you want to make predictions through and click Predictions > Prediction API. On the Prediction API Scripting Code page, you can choose from several scripts for Batch and Real-time predictions. Follow the sample provided and make the necessary changes when you want to integrate the model, via API, into your production application.

Dormant prediction servers

Prediction servers become dormant after a prolonged period of inactivity. If you see the Prediction server is dormant alert, contact support@datarobot.com for reactivation.

Batch prediction snippet settings

To find and access the batch prediction script required for your use case, configure the following settings:

Content Description
1 Prediction type Determines the prediction method used. Select Batch.
2 Interface Determines the interface type of the batch prediction script you generate. Select one of the following interfaces:
  • CLI: A standalone batch prediction script using the DataRobot API client. Before using the CLI script, if you haven't already downloaded predict.py, click download CLI tools.
  • API Client: An example batch prediction script using DataRobot's Python package.
  • HTTP: An example batch prediction script using raw Python-based HTTP requests.
3 Platform
(for CLI interface only)
Determines the OS on which you intend to run the generated CLI prediction script when you select the CLI interface option. Select one of the following platform types:
  • Mac/Linux
  • Windows
4 Show secrets Displays any secrets hidden by ***** in the code snippet. Revealing the secrets in a code snippet can provide a convenient way to retrieve your API key or datarobot-key; however, these secrets are hidden by default for security reasons, so ensure that you handle them carefully.
5 Copy script to clipboard Copies the entire code snippet to your clipboard.
6 Open in a codespace Open the snippet in a codespace to edit it, share with others, and incorporate additional files.
7 Code overview screen Displays the example code you can download and run on your local machine. Edit this code snippet to fit your needs.

Real-time prediction snippet settings

To find and access the real-time prediction script required for your use case, configure the following settings:

Content Description
1 Prediction type Determines the prediction method used. Select Real time.
2 Language Determines the language of the real-time prediction script generated. Select a format:
  • Python: An example real-time prediction script using DataRobot's Python package.
  • cURL: A script using cURL, a command-line tool for transferring data using various network protocols, available by default in most Linux distributions and macOS.
3 Show secrets Displays any secrets hidden by ***** in the code snippet. Revealing the secrets in a code snippet can provide a convenient way to retrieve your API key or datarobot-key; however, these secrets are hidden by default for security reasons, so ensure that you handle them carefully.
4 Copy script to clipboard Copies the entire code snippet to your clipboard.
5 Open in a codespace Open the snippet in a codespace to edit it, share with others, and incorporate additional files.
6 Code overview screen Displays the example code you can download and run on your local machine. Edit this code snippet to fit your needs.

Disable data drift

You can disable data drift tracking for individual prediction requests by applying a unique header to the request. This may be useful, for example, in the case where you are using synthetic data that does not have real-world consequences.

Insert the header, X-DataRobot-Skip-Drift-Tracking=1, into the request snippet. For example:

headers['X-DataRobot-Skip-Drift-Tracking'] = '1'
requests.post(url, auth=(USERNAME, API_KEY), data=data, headers=headers)

After you apply this header, drift tracking is not calculated for the request. However, service stats are still provided (data errors, system errors, execution time, and more).

Open snippets in a codespace

You can open a Prediction API code snippet in a codespace to edit the snippet directly, share it with other users, and incorproate additional files.

To open a Prediction API snippet, click Open in a codespace.

DataRobot generates a codespace instance and populates the snippet inside as a python file.

In the codespace, you can upload files and edit the snippet as needed. For example, you may want to add CLI arguments in order to execute the snippet.

The codespace allows for full access to file storage. You can use the Upload button to add additional datasets for scoring, and have the prediction output (output.json, output.csv, etc.) return to the codespace file directory after executing the snippet. This example uploads 10k_diabetes_small.csv to the codespace as an input file.

To add CLI arguments to the snippet, click Add CLI arguments .

This example references 10k_diabetes_small.csv as the input file for scoring, and names the output file output.csv.

The snippet is now configured to run and return predictions. When you have finished working in the codespace, click Exit and save codespace.

Codespaces belong to Use Cases, so you must specify an existing Use Case or create a new one to save the codespace to. When a Use Case has been selected, click Exit and save codespace again. Your snippet is now saved in a codespace as part of a Use Case.


Updated December 3, 2024