Access denied due to invalid subscription key (Face API)
Asked Answered
G

9

13

I am having trouble using Microsoft Face API. Below is my sample request:

curl -v -X POST "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: 1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd" --data-ascii "{\"url\":\"http://www.mrbeantvseries.co.uk/bean3.jpg\"}"

I use the subscription id from my cognitive services account and I got below response:

{
  "error": {
    "code": "Unspecified",
    "message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."
  }
}

Not sure if I've missed out anything there. Can someone help me on this? Very much appreciated.

Gammy answered 8/2, 2017 at 21:8 Comment(2)
URL: azure.microsoft.com/nl-nl/try/cognitive-services/my-apisSievers
You might want to check this to make sure that you're passing the right key - Where to find my Ocp-Apim-Subscription-Key in Windows azureGnome
S
8

It appears that you've entered your Azure subscription ID instead? In the Azure portal, you can find the API key under 'Keys', shown below:

Azure Portal screenshot

It will be a 32-digit hexadecimal number, no hyphens.

Schorl answered 9/2, 2017 at 2:42 Comment(1)
Hi @cthrash, you are right. Previously I've also tried both of those keys but it returned error. Now that I tried again and it's working. Must be some mistake before. Thanks for pointing in the right direction!Gammy
K
14

I ran into the same problem. I read the API documentation and it states the following.

You must use the same region in your REST API call as you used to obtain your subscription keys.

First, you must find the location of your subscription. In order to find the location of your subscription region, you must go to Cognitive Services -> Properties under the Label Location, you will find your subscription region. See below. enter image description here

Second you must find the correct endpoint to make the call to. For example, if I want to make a call to the Computer Vision API, My location is East US, I will use either key 1 or 2, then I will use the following endpoint East US - https://eastus.api.cognitive.microsoft.com/face/v1.0/detect

You will now be able to have access to the API.

Karlin answered 28/1, 2018 at 1:50 Comment(2)
great bro u saved my life :D thnksCammi
THANK YOU this was the worst bugOre
S
8

It appears that you've entered your Azure subscription ID instead? In the Azure portal, you can find the API key under 'Keys', shown below:

Azure Portal screenshot

It will be a 32-digit hexadecimal number, no hyphens.

Schorl answered 9/2, 2017 at 2:42 Comment(1)
Hi @cthrash, you are right. Previously I've also tried both of those keys but it returned error. Now that I tried again and it's working. Must be some mistake before. Thanks for pointing in the right direction!Gammy
W
7

I had faced the same issue, it seems like there is some problem with the keys generated newly. To fix this you can actually add your endpoint as well, when you create the object for IFaceServiceClient. You can see the code below.

private readonly IFaceServiceClient faceServiceClient = new FaceServiceClient("your key", "Your endpoint");

enter image description here

Whitelaw answered 21/6, 2017 at 17:4 Comment(1)
Yes - I had to add the endpoint. IFaceServiceClient faceServiceClient = new FaceServiceClient(ai.key1, "australiaeast.api.cognitive.microsoft.com/face/v1.0")Rightism
C
2

I ran into a similar problem. I figure it might be helpful to some people, so I am posting it here. (btw Azure support points me to this post here)

I was trying to run through the sample file for ImageSearch of Azure. I was refering to these pages:

I was receiving a mixture of 404 Not Found error & 401 unauthorized error when send requests to the Bing Search resource, using Microsoft.Azure.CognitiveServices.Search.ImageSearch. I figure it must be something wrong with either my credentials or my endpoints.

After struggling with it for hours, reading through posts and talking to Azure support member, I finally find the problems:

  1. The base Uri Endpoint I was assigned on the Azure Keys & Endpoints webpage is incomplete. (https://api.bing.microsoft.com/)
  2. The base Uri Endpoint on the sample tutorial pages was outdated because of the 2020.10.30 transition between Cognitive Services to Bing Search Services. (https://api.cognitive.microsoft.com/bing/v7.0/images/search)

As of 2021.09.22, the correct global base Uri Endpoint for Bing Image Search is: https://api.bing.microsoft.com/v7.0/images/search

Hope this would be helpful to anyone and save mankind some time.

Crum answered 22/9, 2021 at 7:30 Comment(0)
A
1

CesarB is correct. You must create a Resource of Cognitive Service in Azure first and then get the subscription key from it. the region is not always 'westus', it really depends on what region you select when you created the resource. You can also check it on the endpoint of overview of the Resource

Albertson answered 20/12, 2018 at 12:56 Comment(0)
I
0

Endpoint https://westeurope.api.cognitive.microsoft.com/face/v1.0

Endpoint and the subscription key must be consistent.

look at Microsoft Overview for this info!

Intrigant answered 11/10, 2018 at 10:56 Comment(0)
M
0

I was using a wrong header in my Http call and had the same error message

I changed "api-key" header

enter image description here

To be replace by "Opc-Apim-Subscription-Key"

![enter image description here

Microampere answered 22/1 at 13:4 Comment(0)
I
0

My team was getting the same error in Azure AI. Turns out that some services are automatically created in another region if they are not available in your region. Our entire Azure workloads are in Australia, but when we created the document intelligence service, it silently got created in East US.

So when you see the Endpoints & Keys section of your dashboard, it will show where you created it (or where the subscription is, in our case both are the same, Australia), but the actual AI service is running from East US. The only place where we could see this contrasting location was in Cost Management > Cost Analysis > Resources.

It could possibly be because AI services are not rolled out worldwide, so there is a higher probability of they ending up in a different region than where the keys and endpoint are defined. We created a new document intelligence resource directly in East US, and used the keys and endpoint from there, and it started working without any problem. We deleted the old resource.

Also as draco951 mentions above, make sure that the key for the API Key is named Ocp-Apim-Subscription-Key, and not apiKey or api-key (we had made those mistakes too).

Impartible answered 1/8 at 3:20 Comment(0)
E
0

Make sure to use the correct endpoint. I was using vision.cognitiveservices.azure.com/ instead of face.cognitiveservices.azure.com/

Epicardium answered 15/8 at 0:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.