How to fix "azure.core.exceptions.ClientAuthenticationError: (None) Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired" during RAG creation tutorial?

Rebecca Molnar 20 Reputation points
2025-01-13T19:00:08.5666667+00:00

I am trying to follow the steps of the tutorial: https://learn.microsoft.com/en-us/azure/ai-studio/tutorials/copilot-sdk-build-rag

I keep getting the error:

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

Code: None

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

I've triple checked my .env file to make sure everything is correct. The code is a direct copy of what is in the tutorial and I've double checked that everything is in the same region. I've tried re-logging into the CLI to make sure it's not that too. The code doesn't specify an api key, which I'm thinking maybe that's what it needs?

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

Accepted answer
  1. Pavankumar Purilla 3,945 Reputation points Microsoft External Staff
    2025-01-16T12:08:52.35+00:00

    Hi Rebecca Molnar,
    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution.

    Please click "Accept" the answer as original posters help the community find answers faster by identifying the correct answer.

    Issue : How to fix "azure.core.exceptions.ClientAuthenticationError: (None) Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired" during RAG creation tutorial?

    Resolution :
    I had to create an application registration and tie that into my code with the:

    AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

    of the application I just registered into the .env file. Once I figured this out, I was able to run the code without issues.

    Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members.

    Accept answers on Microsoft Q&A | Microsoft Learn

    An accepted answer is the answer that the person who asked the question chooses as the one they think best solves their problem.

    0 comments No comments

0 additional answers

Sort by: Most 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.