ai-center
latest
false
AI Center
Automation CloudAutomation SuiteStandalone
Last updated Oct 10, 2024

Save infrastructure costs using AI Center APIs

With the API requests, you can programmatically change the state of an ML Skill. These APIs could be used even within an automation workflow to deploy and undeploy an ML Skill, optimizing the uptime for infrastructure and saving costs. See the complete set of AI Center APIs documented in swagger.

Note that accountname and tenantname are specific to your account. For more information, see the API list.

You use the AI Center APIs to:

  1. Find the ML Skill ID of sampleClassifierSkill
  2. Stop (undeploy) the ML Skill
  3. Start (redeploy) and verify the status update.

In November 2022, we announced the availability of APIs to programmatically interact with every component within AI Center. You can now manage datasets, train ML models, and deploy ML Skills using APIs, without having to use the User interface.

One of the key use-cases for leveraging APIs is to manage the deployment status of an ML Skill. Depending on the automation, you may not need an ML Skill to be active all the time. Undeploying ML Skills when not in use can help you save on hardware costs (AI units).

The steps to access AI Center APIs are:

  1. Registering an external application (one-time setup)
  2. Generating an authentication token (renew upon expiry)
  3. Making AI Center API calls
Note: The first two steps enforce access control by making sure your application is registered and authenticated

Registering an external application

To use the APIs, your app needs to register as an external application with an AI Center scope.

  1. From the left navigation panel, go to the Admin page and select External Applications.
  2. To add a new external application, select + Add Application

    and name it.

    Note: Onlyconfidential application type can access AI Center APIs.
  3. To enable AI Center scope to the external application:
    1. Select Add scope
    2. Pick AI Center API Access (preview) from the Resource dropdown
    3. Navigate to the Application Scope tab
    4. Select the APIs to which you want to enable access to.
    In the example below, all the APIs are selected for simplicity, but you can choose to assign specific APIs access to specific external applications.


  4. Select Add. A pop up with App ID and an App Secret is generated.
    Tip: You can view the App ID and App Secret anytime from the Edit External application. These credentials are used to generate an authentication token in the next step. See additional information on managing external applications.


Generating an authentication token

For authentication and secure access, the external application requests an access token from the UiPath® Identity Server. The generated authentication token expires in one hour, upon which you need to regenerate a new auth token.

If you want to use Postman, you can register for free and choose to use either the Postman web-based interface or the downloadable application. See the official Postman website.

  1. Generate a POST request to the Identity Server endpoint https://cloud.uipath.com/identity_/connect/token that includes the following in the body of the request.
    client_id: App ID from previous step
    client_secret: App Secret from previous step
    grant_type: “client_credentials”client_id: App ID from previous step
    client_secret: App Secret from previous step
    grant_type: “client_credentials”
  2. Set grant_type to client_credentials.
Use the application/x-www-form-urlencoded content type for Postman.


This request generates an auth token similar to the one below, listing the permissions enabled for this external application. Use this auth token when making AI Center API calls.


See additional information on credentials and auth tokens.

Making AI Center API calls

The API calls adhere to the following structure: https://cloud.uipath.com/accountname/tenantname/aifabric_/ where “accountname" and “tenantname” are specific to your account. Most APIs need the following information:
  1. Account ID and Tenant ID. You can find the account and tenant information in the profile info section within the tenant. See profile information.
  2. Authorization. The authorization field should be populated with the auth token generated in the previous step.
    Important: When using the auth token, prefix it with Bearer as in the screenshot below.
Now you can access specific APIs. Use sampleClassifierSkill for this example. In the ML Skills list, you can see this skill exists and is currently in the Available state.

Find ML Skill details

Using the GET ML Skills call, you can fetch a list of all ML Skills within the account and tenant. You can also add the ML Skill name as part of the query to search for a specific ML Skill and retrieve its details. In this case, you find the ML Skill idfor the sampleClassifierSkill
GET /ai-deployer/v1/mlskills?name=sampleClassifierSkill


In the response below, the key fields are highlighted in yellow. Double check that the sampleClassifierSkill is in the Available state. The ML Skill id is used in the subsequent APIs to update the state.


Stop ML Skill

To stop an ML Skill:

  • Request query should contain the stop update action and ML Skill id
  • Header should contain account, tenant and auth info
PUT /ai-deployer/v2/mlskills/stop/{mlSkillId}


The response shows that the ML skill status change was successful:


Checking the UI, you can verify that sampleClassifierSkill was undeployed.


Resume ML Skill

To restart (deploy) the ML Skill, make the API calls with the updateType set to Resume.
POST /ai-deployer/v1/mlskills/{mlSkillId}?updateType=RESUME
{ "deploymentsRequired": 1, 
"gpuRequired": 0, 
"mlPackageVersionId": <package-version-id>, 
"processor": "CPU", 
"publicSkill": false, 
"autoUpdate": false, 
"inactivityPeriodInDays": 7, 
"replicas": 1, 
"requestMemory": 2, 
"requestCPU": 0.5, 
"limitMemory": 9, 
"limitCPU": 2 
}{ "deploymentsRequired": 1, 
"gpuRequired": 0, 
"mlPackageVersionId": <package-version-id>, 
"processor": "CPU", 
"publicSkill": false, 
"autoUpdate": false, 
"inactivityPeriodInDays": 7, 
"replicas": 1, 
"requestMemory": 2, 
"requestCPU": 0.5, 
"limitMemory": 9, 
"limitCPU": 2 
}


From the response, you can see that the request was successful, and the skill state was updated to Deploying.


Wait for the Skill to become available, and check the ML Skill status using the GET ML Skill details API.


From the response, the ML Skill is now deployed and Available. Verify the skill availability in the UI. Now your automations can leverage the deployed ML Skill sampleClassifierSkill within workflows, to make predictions.




Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.