Sitemap

Member-only story

Authenticate your Azure OpenAI Based App Using Microsoft Entra ID & Managed Identity

5 min readSep 17, 2024

--

If you’re using Azure OpenAI then you must be aware that the most common and easiest way to authenticate our application is using app-key.

generated from bing

The key-based authentication approach is very popular because it is very straightforward. Let’s have a quick look at the below code snippet:

from openai import AzureOpenAI
client = AzureOpenAI(
api_key= ‘KEY’,
api_version=”VERSION",
azure_endpoint = ‘ENDPOINT’ )

response = client.completions.create(model=’MODEL’, prompt=’PROMPT’, max_tokens=80)
print(response.choices[0].text)

The above code snippet constructs the AzureOpenAI client object using api-key, api-version, and endpoint. Then, this object makes a call to the completion endpoint with the required parameters.

Of course, app key works very well for the experimentation purpose and is not very well suited for enterprise grade applications which will soon be in production.

So, why should we never use keys to authenticate Azure OpenAI in production?

Key reasons for not using key-based authentication

In a production capacity, it is generally not recommended to use keys for Azure OpenAI authentication and there are…

--

--