POST https://lasttesttest.cognitiveservices.azure.com/vision/v3.1/ocr?detectOrientation=false 401 (Unauthorized)

Ali MTW 0 Reputation points
2024-02-18T15:42:48.0833333+00:00

How to fix this

const endpoint = "https://lasttesttest.cognitiveservices.azure.com/vision/v3.1/ocr?detectOrientation=false";

    fetch(endpoint, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/octet-stream',
            'Ocp-Apim-Subscription-Key': apiKey
        },


POST https://lasttesttest.cognitiveservices.azure.com/vision/v3.1/ocr?detectOrientation=false 401 (Unauthorized)

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,650 questions
{count} votes

1 answer

Sort by: Most helpful
  1. dupammi 8,615 Reputation points Microsoft External Staff
    2024-02-19T11:36:37.6266667+00:00

    Hi @Ali MTW

    Thank you for using the Microsoft Q&A forum.

    Regarding your error while using the REST API URL, I tried to repro your issue using POSTMAN tool. Kindly issue the POST request in the postman to the OCR API Azure Cognitive Services Endpoint. Once the POST request was done in the Postman, we can check the results. Please also provide the API key, content type etc in the POST request and click on "SEND" button in postman. Give the below values in POST request Header. In Body select the binary option and browse for the image file. see the below screenshot, in which the POST request was successful from my side. User's image To fix the "401 Unauthorized" error when accessing the OCR API of Azure Cognitive Services, you need to provide valid credentials, ensure the subscription key is correctly provided in the request header, verify you have the necessary permissions, and check if the endpoint URL is correctly configured. To ensure you have necessary roles (Cognitive Services OCR Contributor or owner role) etc., please "Run" a test from the studio itself.

    If the issue persists, please raise a support request through Azure portal for further assistance.

    I hope you understand! Thank you.


    Please do not forget to click Accept Answer and Yes for was this answer helpful, wherever the information provided helps you. This can be beneficial to other community members.

    0 comments No comments

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.