Microsoft Cognitive Services - Computer Vision: Invalid Subscription Key

I am trying to use the Computer Vision API from Microsoft Cognitive Services. However, my keys don't seem to work. I created an account using a free trial of this API and got two keys from it. Trying to use the key with the ProjectOxford.Vision SDK always gives:

Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription.

I tried the API console , however, I get the same error with my key in the field Ocp-Apim-Subscription-Key

. I tried both keys and none of them work. I even got the free version of the Face API and tried console , but ran into the same problem with my keys. I've even tried different datacenters, but they all seem to return the same error.

It must be some kind of key problem and then correct? This may not be a problem for my C # code as the console doesn't work either. And since it doesn't work in the API console, there is nothing else I can do to rule out any other possibilities? I'm not sure what else I can do to debug this. I would like to regenerate my keys (I saw a tutorial video showing an older interface for getting API keys and they had a "regenerate" link) but I no longer see a way to do it.

I just made an account and signed up for the APIs, so I might not be over quota. Is there something else I need to do to enable these keys or something else?

+3


source to share


4 answers


If you are using free trial keys obtained from azure.microsoft.com. You must change the scope of the API endpoint to westcentralus

. The previous default region is westus

and I think this is the cause of the invalid key problem.



0


source


I was able to work around the "Access Denied" issue by doing the following:



(I got this link from the Cognitive Services Test Control Panel).

Take a look at the request template in the dashboard and you can tell how to use the api.

+2


source


Even when @ Xuan Hu's answer correctly answers the solution, I scratched my head several times trying to figure out how to change the endpoint. Here are my 2 cents:

  • Go to portal.azure.com, in your Cognitive Services> General Information> End Point subscription panel, note the URL. You need it.

  • Find in the code of the VisionAPI samples where the VisionServiceClient is instantiated:

    VisionServiceClient VisionServiceCliente = new VisionServiceClient (SubscriptionKey);

and change the url you found in Azure:

VisionServiceClient VisionServiceCliente = new VisionServiceClient(SubscriptionKey, StringOfMyURLTakedFromPortal);

      

This worked for me.

+2


source


FYI, there is a blog post that covers all 401 Access Denied scenarios, including free API keys and region-specific API endpoint. Add it here for people in the future who find this SO post - https://blogs.msdn.microsoft.com/kwill/2017/05/17/http-401-access-denied-when-calling-azure-cognitive- services-apis / .


Using the wrong regional endpoint

Most of the Cognitive Services APIs are region specific, which means that when you create an API account, you choose in which realm you want to create the account. These APIs have region specific endpoints such as westus.api.cognitive.microsoft.com or eastus2.api.cognitive.microsoft.com and the API key for an account created in one region will only work using the endpoint for that particular region. This means that if you create an API account in Western US countries, you will not be able to call the eastus2.api.cognitive.microsoft.com API endpoint.

You can check the region and endpoint in the Azure Management Portal.

enter image description here

Trial API Keys

Free trial API keys have a 30-day expiration date and the same region and version restrictions. If you are using trial keys, you can go to https://azure.microsoft.com/en-us/try/cognitive-services/my-apis/ to manage API keys (if you are not already logged in, just click one from the Create buttons and you can go through the login wizard and view the existing API keys) and you will also see the expiration date and endpoint. enter image description here

+1


source







All Articles