What causes Error code: 401 - {'statusCode': 401, 'message': 'Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired.'}?
Can someone give an example? I matched the api version the same as the model deployment endpoint's target uri- for example, (Note that the real address is masked with [azureopenai-resourcename] since everyone's case will be different) https://[azureopenai-resourcename].openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview
Then I set the required environment variables like
export AZURE_OPENAI_API_KEY="<replaced with my key>"
export AZURE_OPENAI_ENDPOINT="https://[azureopenai-resourcename].openai.azure.com/"
export OPENAI_API_TYPE="azure"
export OPENAI_API_VERSION="2024-08-01-preview" ## This is to match the api version that shows up in the target uri. But it still gives the error messages like:
INFO:httpx:HTTP Request: POST https://[azureopenai-resourcename].openai.azure.com//openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview "HTTP/1.1 401 Unauthorized"
Error code: 401 - {'statusCode': 401, 'message': 'Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired.'}
When I use LangChain to load embedding model, it works ok, but while using reranker using gpt model(s) it makes a problem. I tested with export OPENAI_API_TYPE="openai" and used my personal account (in this case it didn't need any other auth other than OPENAI_API_KEY. So it seems the langchain's rerank works and somehow it breaks when azure credentials are passed. So other than those envs (AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, OPENAI_API_TYPE, OPENAI_API_VERSION), what "Access token" is required?? And what is https://cognitiveservices.azure.com?? Do we need to set up another endpoint other than the model deployment (as above uri shows)?