Azure OpenAI API returns 401 Unauthorized with audience error: "https://cognitiveservices.azure.com" expected

Magnus Vinterhav 0 Reputation points
2024-11-15T10:42:52.6966667+00:00

Issue: I’m receiving a 401 Unauthorized error when trying to access the Azure OpenAI API. The error message specifically mentions:

"Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired."

Details:

  • Resource: Azure OpenAI deployed in West Europe
  • Endpoint Structure: `https://
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,306 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pavankumar Purilla 1,230 Reputation points Microsoft Vendor
    2024-11-15T17:46:22.4366667+00:00

    Hi Magnus Vinterhav
    Greetings & Welcome to Microsoft Q&A forum! Thanks for posting your query!

    Apologies for the issue that you are facing.

    The error message you are seeing indicates an issue with the authentication process when trying to call the Azure OpenAI API.

    This could happen for several reasons, such as your API key is missing or invalid, or the endpoint is incorrect.

    Please make sure that you have a valid API key and endpoint for GPT-4o.

    Also, make sure that you are using latest and updated python versions, Openai and api_version.

    See the similar issues below which has been addressed and let me know if that helps.

    https://learn.microsoft.com/en-us/answers/questions/1685378/how-to-use-gpt-4o-without-azure-cognitive-search?page=0&orderby=Helpful#answers.

    Failed to call Azure OpenAI API: failed with error:invalid_api_key.

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.


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.