Cloudera AI API v2
Cloudera AI provides a REST API for managing projects, jobs, and runs. You can use the API to integrate Cloudera AI with third-party workflow tools or to automate operations from the command line.
Cloudera AI Workbench uses long-lived API tokens from Anywhere Cloud for /api/v2 API calls, with token validation
handled by Knox. These API tokens do not expire automatically. To revoke access, users must
revoke the token in the Anywhere Cloud console by navigating to and selecting Revoke Key.
API v2 supersedes the legacy Jobs API. For more information about the Jobs API, see Jobs API in the Related information section, below.
Viewing the API specification
You can view the complete API specification in REST API v2 Reference documentation. For the reference link, see the Related information section.
- REST API specification:
https://<domain name of Cloudera AI instance>/api/v2/swagger.html - Python API specification:
https://<domain name of Cloudera AI instance>/api/v2/python.html
swagger.json
endpoint.Quickstart
API key authentication
- In the Cloudera console, click the AI Workbench tile. The Cloudera AI Workbenches page displays.
- Click on the name of the workbench. The Workbenches Home page displays.
- In , click Create API Key.

The Confirm create API Key window is displayed.

- Click Create.
Using curl from the Command line
To simplify API requests with curl, store your Cloudera AI domain and API key in environment variables.
- Copy the API key from Cloudera AI.
-
Open a terminal and store the API key in an environment variable.
On unix-based systems:
export API_KEY=<paste the API key value here> -
Copy the Cloudera AI domain name from your browser address bar.
On unix-based systems:
export CDSW_DOMAIN=<domain>(a value like:ml-xxxx123456.com).
Sample API requests
- List available projects:
curl -X GET -H "authorization: Bearer $API_KEY" https://$CDSW_DOMAIN/api/v2/projects | jqThe
jqutility formats the JSON output for improved readability. - Access an application using the API
key:
curl -X GET -H "authorization: Bearer $API_KEY" https://$CDSW_APP_DOMAIN - Filter projects by
keyword:
curl -X GET -H “authorization: Bearer $API_KEY” https://$CDSW_DOMAIN/api/v2/projects?searchFilter=demo | jqThis command returns only projects whose name or description contains the word
demo.Paginate results by limiting each page to two projects:
?pageSize=2The response includes a
next_page_tokenvalue. Use this token to retrieve the next page:?pageSize=2&pageToken=<token>
Using the Python client library
To use the Cloudera AI API in Python applications, first install the Python client library and configure it to connect to your Cloudera AI instance.
Install the client library:
pip3 install https://$CDSW_DOMAIN/api/v2/python.tar.gz
Include the following code, and specify the values for [***CDSW_DOMAIN***] and [***API_KEY***] with variables or values for your installation.
# In a session:
api_instance = default_client()
# Outside a session:
default_client("https://"+cluster, APIKEY)
You can then call API methods, such as listing projects:
projects = api_instance.list_projects()
The API returns objects whose values are accessed as attributes. Use dot notation instead of dictionary-style bracket notation.
myproj = client.create_project(...)
# This doesn't work:
myproj["id"]
# But this does
myproj.id
Check the Python documentation for a full list of the available API commands.
Using the Python client library in the REPL
The following example shows a simple Python script that configures the API client using command-line arguments. You can run the script locally to start an interactive Python session for testing API commands.
Create a file named demo.py with the following content:
import clap
import argparse
parser = argparse.ArgumentParser(description=‘Test the generated python package.’)
parser.add_argument(“—host”, type=str, help=‘The host name of your workbench”)
parser.add_argument(“—token”, type=str, help=‘Your API key”)
args = parser.parse_args()
config = clap.Configuration()
config.host = ars.host
client = cmlapi.ApiClient(config)
client.set_default_header(“authorization”, “Bearer “ + args.token)
api = cmlapi.Apiapi(client)
python3 -i demo.py —host https://$CDSW_DOMAIN —token $API_KEYThis command starts a Python REPL with the api object already initialized.
>>> api
<cmlapi.api.api_api.ApiApi object at 0xlasjoid>
>>> api.api_list_projects()
api.api_list_projects(searchFilter=‘demo’)
api.api_list_projects(page_size=2)
api.api_list_projects(page_size=2, page_token=‘<token value>’)