Microsoft Azure AI Engineer Associate AI-102 Practice Question
You are developing an Azure Function written in Python that must send chat completion requests to a GPT-4 deployment named "chat-gpt4" in the Azure OpenAI resource "lit-openai". The security team prohibits storing service access keys in your source code, configuration files, or environment variables. You decide to use the system-assigned managed identity of the function for authentication. Which approach should you implement to meet the requirements?
Instantiate azure.ai.openai.OpenAIClient with DefaultAzureCredential, and assign the function's managed identity the Cognitive Services OpenAI User role on "lit-openai".
Use the openai Python package and set openai.api_key to the managed identity's client ID while pointing openai.api_base to the Azure endpoint.
Retrieve the Azure OpenAI resource key from Azure Key Vault at startup and expose it as the OPENAI_API_KEY environment variable.
Add the managed identity to the Reader role on the resource group and create OpenAIClient with AzureKeyCredential initialized to an empty string.
The Azure Function can acquire an Azure AD access token for Azure OpenAI through its system-assigned managed identity. When you instantiate OpenAIClient with an Azure AD token credential (for example, DefaultAzureCredential), the SDK handles token acquisition transparently. For the token to be accepted, the managed identity must be granted the Cognitive Services OpenAI User role on the Azure OpenAI resource. Passing the managed identity's object ID as an API key (or retrieving the key from Key Vault) would still rely on key-based authentication, which the security team disallows. Assigning the Reader role or using AzureKeyCredential does not enable token-based authentication.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is DefaultAzureCredential?
Open an interactive chat with Bash
What is the Cognitive Services OpenAI User role and why is it necessary?
Open an interactive chat with Bash
How does a managed identity work in Azure Functions?
Open an interactive chat with Bash
Microsoft Azure AI Engineer Associate AI-102
Implement generative AI solutions
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .