question

MarcusBointon-6022 avatar image
0 Votes"
MarcusBointon-6022 asked MarcusBointon-6022 commented

Speech API rejects requests with 401 whether using key or token

I'm trying to call the speech API. The docs say I can use either a Ocp-Apim-Subscription-Key header containing my subscription key directly, or I can request an access token with a call to https://<REGION_IDENTIFIER>.api.cognitive.microsoft.com/sts/v1.0/issueToken, to obtain a JWT that I can then include in subsequent requests in an Authorization: Bearer <token> header. However, neither works. I can successfully obtain an access token (which I assume means that my key is correct), but then calls to the API endpoint using either authentication mechanism are rejected with a 401 error and no other info (content length of the response is 0). I am using the same region identifier for both calls. Is there something else I have to do?


azure-speech
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MarcusBointon-6022 Could you post the actual API call to the service where the 401 error response is received? Depending on which API you would call the URI should be something like below:

 https://<REGION_IDENTIFIER>.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1


0 Votes 0 ·

I'm getting the token from:

 https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken

and calling the API at

 https://westeurope.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-CA

The only obvious difference is the language param.

0 Votes 0 ·

I tried posting my other note as a comment but this site wouldn't accept it - the only thing that worked was posting it as a answer

0 Votes 0 ·
romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered MarcusBointon-6022 commented

@MarcusBointon-6022 Could you please clarify the public API you are referring to? I am referring to API similar to this:

 https://<region>.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1

To simplify our conversation and demonstrate its usage I am using the API in the following way to use the service.

  1. Use the keys of the speech resource created in Azure to get the bearer token. API used https://<REGION_IDENTIFIER>.api.cognitive.microsoft.com/sts/v1.0/issueToken

  2. Used the bearer token along with a wav file as input to get the detailed response of the text. API used https://<region>.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1

90257-image.png

90258-image.png

If I use the same API with the key rather than the token, I get the same result.

90344-image.png


image.png (145.6 KiB)
image.png (105.5 KiB)
image.png (117.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks. I had got to this point after finding that I did need to use separate keys for each service, and it is now working. What is also confusing is why for the vision API I get a URI that points at my vision resource, but the URI for my speech resource points at the public service. The keys for my own resource work for the public API, even though I was required to create a unique URI for my resource. Does the public URI get mapped to my resource through the key? Why isn't it consistent across services/resources?


I've not tried the reverse combination - is the token-based auth mechanism supported by the vision API?

0 Votes 0 ·
MarcusBointon-6022 avatar image
0 Votes"
MarcusBointon-6022 answered romungi-MSFT commented

I think the problem is with my subscription key. When I set things up I just wanted to be able to auth and call a vision API, but I had to create a resource group and a resource of my own before I could do that. This was very confusing, and not something I expected to have to do, but I got it running. The subscription key I'm trying to use for speech is the one I use for that. I tried using it for another service and it didn't work:

 curl -X GET 'https://westeurope.api.cognitive.microsoft.com/bing/v7.0/search?q=Welsch%20Pembroke%20Corgis' -H 'Ocp-Apim-Subscription-Key:<my key>'

Unlike the speech API's bare 401, this gives me an understandable error:

 {"error":{"code":"401","message": "The Search Operation under Web Search API - v7 is not supported with the current subscription key and pricing tier ComputerVision.F0."}}

I don't have any other keys. If this is the wrong key, why does the issueToken endpoint work? Do I have to register a new account to get a different key?

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MarcusBointon-6022 Did you create a common cognitive services resource instead of the speech resource?
Some of the cognitive services support common resource so users create a common resource and use it for different services under cognitive services. But as the services evolved this functionality became limited and the general thumb rule is to create the required cognitive service resource and use respective keys instead.


0 Votes 0 ·

The resource I have was made according to the guide you pointed at, and is labelled both "Cognitive services", and also "Computer vision". I have no idea whether this includes speech services or not. However, I wouldn't expect it to need to because the speech API endpoint I'm using is not one that points at my resource. How can I get a key that works with the public speech API, which doesn't appear to have anything to do with my resources? Why does the token endpoint work with what seems to be the wrong key? Isn't that a bug? If I try to add a new resource for speech, there are no Microsoft services available, only third parties from a marketplace. It's all such a mess.

0 Votes 0 ·

The speech resource in marketplace is as shown below:

89913-image.png

These steps should help you create the correct resource and use the keys of this resource.

The token endpoint is a common cognitive services endpoint which provides a valid bearer token for a cognitive services resource key. This token is validated for an API call to the actual service.


0 Votes 0 ·
image.png (99.2 KiB)
Show more comments