4

I'm trying to use the Computer Vision API from Microsoft's Cognitive Services. However, my keys don't seem to be working. I created an account using the free trial of that API and got the two keys from it. Trying to use the key with the ProjectOxford.Vision SDK always yields:

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 Ocp-Apim-Subscription-Key field. I tried both keys and neither of them work. I even got the free version of Face API and tried its console, but encountered the same issue with its keys. I even tried different datacenters, but they all seem to return the same error.

This would need to be some problem with the key then right? This can't be a problem with my C# code, since the console doesn't work either. And since it's failing in the API console, there's nothing more I can do to rule out any other possibilities is there? I'm not sure what else I can do to debug this. I'd like to regenerate my keys (I saw a tutorial video which showed an older UI of getting the API keys and they used to have a "regenerate" link) but I don't see a way of doing that anymore.

I only just made the account and registered for the APIs, so there's no way I'd be over quota. Is there something else I need to do to enable these keys or something?

Douglas Parker
  • 1,164
  • 11
  • 20
  • Just wait 5 minutes. For some good (i guess) reason, the key isn't immediately usable. There's a note about this in the API key page. – evilSnobu May 21 '17 at 10:38
  • Douglas, did you get this to work? Are you sure the endpoints you're hitting correspond to the keys you have (e.g. West US)? – Maria Ines Parnisari May 21 '17 at 19:14
  • Running into the same issue (for cognitive api, specifically recognizeText), it's been about 15 minutes since I created an account and signed up for a key. Any help would be greatly appreciated. – Sirpingalot May 22 '17 at 00:55

5 Answers5

2

I managed to skirt around the issue of 'Access Denied' by performing the following actions:

  1. I created a free Azure account
  2. I set up an instance of the Cognitive Services Api (this generated a pair of new keys for me to use)
  3. Utilizing the new key, I had to use the following link: https://westus.api.cognitive.microsoft.com/vision/v1.0/ocr

    Instead of

    https://westus.api.cognitive.microsoft.com/vision/v1.0/recognizeText

(I obtained this link from the Cognitive Services Test Dashboard).

Look at the request pattern on the test dashboard and you should be able to tell how to use the api.

Sirpingalot
  • 447
  • 1
  • 5
  • 11
  • Same; for me the settings (Quick Start) for ComputerVisionAPI in the cognitive services displays only the root path for ex: https://westeurope.api.cognitive.microsoft.com/vision/v1.0 – hB0 Apr 09 '18 at 08:33
2

Even when @Xuan Hu response states correctly to the solution, I scratched my head some time trying to figure out how to change the end point. Here are my 2 cents:

  1. Go to portal.azure.com, in the dashboard of your subscription to the Cognitive Services > General Information > End Point take note of the URL. You need it.

  2. Find in the code of your VisionAPI samples where the VisionServiceClient is instantiated:

    VisionServiceClient VisionServiceCliente = new VisionServiceClient(SubscriptionKey);

and change including the URL that you found in Azure:

VisionServiceClient VisionServiceCliente = new VisionServiceClient(SubscriptionKey, StringOfMyURLTakedFromPortal);

That worked for me.

Fidel Orozco
  • 998
  • 11
  • 19
1

If you are using the free trial keys got from azure.microsoft.com. You need to change the API endpoint region to westcentralus. The previous default region is westus and I think that is the reason of the invalid key problem.

Xuan Hu
  • 856
  • 8
  • 22
  • Switching to West Central did the trick. I don't know why it set my API keys to point there, I live in California so West US would make more sense. I don't think I picked a particular endpoint unless I missed an input somewhere. Thanks for the tip. – Douglas Parker May 22 '17 at 03:21
  • @DouglasParker it is a fixed setting in azure.microsoft.com. I have to admit that it is not so user-friendly. But there does not seems to have a perfect solution to balance the simplicity and flexibility. – Xuan Hu May 22 '17 at 12:32
  • Ah, that would explain it. The error message could just say "Wrong endpoint", though maybe that's not possible for technical reasons. Otherwise when I register for the key is should maybe have let me select the endpoint? Or at least list `westcentralus` as the required endpoint due to the trial I was in? I dunno, it definitely seems avoidable somehow. – Douglas Parker May 22 '17 at 20:18
  • @Xuan Hu What do you mean with "change API endpoint region"? In the case of VisionServiceClient C# wrapper does not exist any property ""EndPoint"... or is someting that mus be changed in the Azure portal? – Fidel Orozco May 22 '17 at 23:54
  • @FidelOrozco If you are using Azure Portal, the region is chosen when you acquiring the key. When using SDK, it depends on whether the SDK itself supports region settings. For Version SDK, please refer to the source code here: https://github.com/Microsoft/Cognitive-Vision-Windows/blob/master/ClientLibrary/VisionServiceClient.cs#L131 – Xuan Hu May 23 '17 at 03:21
  • Sorry for the typo: S/Version/Vision/g – Xuan Hu May 23 '17 at 03:29
1

FYI, there is a blog post that covers all of the 401 Access Denied scenarios, including this one regarding the free API keys and region specific API endpoint. Adding it here for folks 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 incorrect regional endpoint

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

You can verify the region and endpoint in the Azure management portal.

enter image description here

Trial API Keys

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

kwill
  • 10,867
  • 1
  • 28
  • 26
0

One thing to remember if using Postman to get the results is to use GET and put your keys in the Header.

Dr T
  • 504
  • 1
  • 7
  • 20