Skip to main content

Authenticating Azure OpenAI with Managed Identity

· 3 min read

When developing a Python application that interacts with Azure OpenAI, you may want to authenticate with an API key for testing, however in Production, you should use Managed Identities within Microsoft Azure.

In this article, we will look at how to authenticate with Azure OpenAI using an API key in Python for local development, then using an environment variable switch to authenticating using managed Identities.

Request is badly formatted Error with Azure OpenAI

· 2 min read

When attempting to call Azure OpenAI using a Managed Identity, you may encounter the following error:

warning
ERROR:root:Error generating response: Error code: 400 - {'error': {'code': 'Request is badly formated', 'message': 'Resource Id is badly formed or from wrong namespace: NA'}}
2024-11-26T18:57:08.224640325Z ERROR:root:Response content: b'{"error":{"code":"Request is badly formated","message":"Resource Id is badly formed or from wrong namespace: NA"}}'