REST API Authentication Error: Azure AI

Tominaga, Kohei/富永 航平 25 Reputation points
2023-11-01T06:54:12.3+00:00

Hello

I am a beginner about Azure services and learning with free subscription.
I am trying to use Text Analytics by calling REST API but it failed with an error.

Could you please help me to do troubleshooting?

Request body:
{Content-Length=2047, Authorization=Bearer 59xxxxxxxxxxxxxdfd, Content-Type=application/json, X-SNC-INTEGRATION-SOURCE=66cce6f7db88bb402f68c59705961974, User-Agent=ServiceNow/1.0, Host=xxx-xxxxxx.cognitiveservices.azure.com}
Request body:

{
  "displayName": "Document Abstractive Summarization Task Example",
  "analysisInput": {
    "d**body truncated**

Response header:
{Content-Length=161, Content-Type=application/json, apim-request-id=d3208fa5-3554-4387-8a44-1974de3a85cf, Strict-Transport-Security=max-age=31536000; includeSubDomains; preload, x-content-type-options=nosniff, Date=Wed, 01 Nov 2023 06:28:19 GMT}
Response body:
{ "statusCode": 401, "message": "Unauthorized. Access token is missing, invalid, audience is incorrebody truncated

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,832 questions
0 comments No comments
{count} votes

Accepted answer
  1. romungi-MSFT 45,721 Reputation points Microsoft Employee
    2023-11-01T10:34:51.17+00:00

    @Tominaga, Kohei/富永 航平 Are you trying the language service document summarization API?

    Based on the error, it looks like an authentication issue where you have tried to use the Bearer token with the request but the token seems to be invalid. How did you generate the bearer token of your language resource?

    Usually, the bearer token is generated by the issue token API which is used for some scenarios of AI services. In this case, you can actually use the subscription key of your resource in the header to pass the request. You can get the subscription key from the resource page on Azure portal from the Keys + Endpoint blade. Use this key with this header to POST the request.

    -H Ocp-Apim-Subscription-Key: <your-language-resource-key>"

    A sample request is mentioned here for reference.

    curl -X GET https://<your-language-resource-endpoint>/language/analyze-text/jobs/<my-job-id>?api-version=2022-10-01-preview \
    -H "Content-Type: application/json" \
    -H "Ocp-Apim-Subscription-Key: <your-language-resource-key>"\ 
    -d \ 
    '
    {
    <body of request>
    }'
    

    I hope this helps!!

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Azar 22,860 Reputation points MVP
    2023-11-01T10:00:34.22+00:00

    HI Tominaga

    Seems like you are having error with the api endpoints, Ensure that the API key you're using in the "Authorization" header is correct and hasn't expired this might be the problem. You can obtain the API key from the Azure portal by going to your Text Analytics resource and looking for the "Keys and Endpoint" section. in that section you will find 2 keys use any one of them and hopefully it works this time.

    If this helps kindly upvote and accept the answer for assistance ping here thanks much.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.