Search code examples
azure-cognitive-servicesazure-sdkmicrosoft-custom-visionazure-sdk-js

Access denied due to invalid subscription key or wrong API endpoint (Cognitive Services Custom Vision)


I'm trying to connect to my Cognitive Services resource but I'm getting the following error:

(node:3246) UnhandledPromiseRejectionWarning: Error: Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.

I created the the resource with kind CognitiveServices like this:

az cognitiveservices account create -n <name> -g <group> --kind CognitiveServices --sku S0 -l eastus --yes

Using kind CustomVision.Training didn't work too.

I have already looked at this answer but it is no the same problem. I believe I am entering the correct credentials and endpoint.

I checked both Azure Portal and customvision.ai resource, I'm using the correct URL and key, but it is not working.

enter image description here

I even tried reseting the key but also it had no effect.

enter image description here

import { TrainingAPIClient } from "@azure/cognitiveservices-customvision-training";
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");

const cognitiveServiceCredentials = new CognitiveServicesCredentials("<MY_API_KEY>");
const client = new TrainingAPIClient(cognitiveServiceCredentials, "https://eastus.api.cognitive.microsoft.com");
const projects = client.getProjects()

I was also able to run it using the REST API, got HTTP 200.

enter image description here


Solution

  • The correct credentials object is this one:

    import { ApiKeyCredentials } from "@azure/ms-rest-js";
    

    Documentation updated, full discussion at #10362