The Azure Cognitive Services SDK is a set of pre-built services that enable developers to easily and quickly integrate AI capabilities into their applications. It provides a wide range of cognitive services including computer vision, language understanding, speech, and search APIs.
Recently whilst using the Azure Cognitive Services SDK recently, I encountered the below error while trying to consume the Cognitive Services Computer Vision API using the Dotnet SDK.
If you’ve also encountered the same error then you are in luck, because in this post I’ll share the solution that worked for me.
Operation returned an invalid status code ‘Unauthorized’
The error initially left me scratching my head because I was sure that I was using the correct connection details for the Cognitive Services service… However, after some trial and error, I eventually found the source of the problem…
Microsoft offers a variety of Cognitive Service API’s for consumption e.g. Face API, Computer Vision API, etc. Although it may not be immediately apparent, it is important that you choose the correct Azure Resource Type to match the corresponding Cognitive Services API that you are using, otherwise, you’ll get the “Unauthorized” error, as I unexpectedly found out!
Once I used the correct Cognitive Services Dotnet SDK with my Azure Cognitive Services resource the issue was resolved. Yay!
Well I hope this solution has also worked for you. If you find any other solutions, feel free to post them in the comments below to help others out there.
Happy coding! 🙂
- How to: Use GitHub Actions with OIDC to Authenticate with Azure - 16th November 2023
- Solved: Intermittent SharePoint Framework Caching and 404 deployment errors - 17th August 2023
- Solved: Azure Functions There is not enough space on the disk - 21st July 2023