Skip to content
background-image background-image

Using Using Azure Cognitive Services

This example shows how to use Azure Cognitive Services module.

Most APIs require authorization provided by @azure/identity module which is imported as azure.identity

Authorization using DefaultAzureCredential class is not supported, you can use ClientSecretCredential

@azure/arm-cognitiveservices module is imported as azure.cognitiveServices

List accounts

const { ClientSecretCredential } = azure.identity;
const { CognitiveServicesManagementClient } = azure.cognitiveServices;

const account = "<account>";
const subscriptionId = "<subscription ID>";
const clientSecretCredential = new ClientSecretCredential(
  "<tentant-id>",
  "<client-id>",
  "<client-secret>"
);

const cognitiveSericesManagementClient = new CognitiveServicesManagementClient(
  clientSecretCredential,
  subscriptionId
);

const resArray = new Array();
for await (let item of cognitiveSericesManagementClient.accounts.list()) {
  resArray.push(item);
}

See Azure CognitiveServicesManagement client library for JavaScript for full examples.