AI-102 Implement generative AI solutions Practice Question
Exhibit
Refer to the exhibit.
$response = Invoke-RestMethod -Uri "https://myfoundry.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2024-02-15-preview" -Method Post -Headers @{
"Authorization" = "Bearer my-key"
} -Body (ConvertTo-Json @{
messages = @(
@{ role = "system"; content = "You are an AI assistant." },
@{ role = "user"; content = "Tell me a joke." }
)
max_tokens = 50
temperature = 0.7
})Refer to the exhibit. A developer runs this PowerShell script to call Azure OpenAI. The script fails with an authentication error. What is the most likely cause?
⚠ Common exam trap
A common mix-up: candidates confuse Azure OpenAI's API key authentication with Azure AD token authentication, assuming 'Authorization: Bearer' is always correct, when in fact the header name differs based on the authentication method.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The script uses the wrong HTTP header; it should use 'api-key' instead of 'Authorization: Bearer'.
The script uses 'Authorization: Bearer' header, but Azure OpenAI requires the API key to be passed in the 'api-key' header. The 'Authorization: Bearer' header is used for Azure AD token-based authentication, not for direct API key authentication. Since the script is using an API key (as indicated by the PowerShell script), the correct header is 'api-key'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
The script uses the wrong HTTP header; it should use 'api-key' instead of 'Authorization: Bearer'.
Why this is correct
Azure OpenAI uses the 'api-key' header for key-based authentication.
- ✗
The script uses the wrong HTTP method; it should use GET.
Why it's wrong here
Chat completions require POST.
- ✗
The API version is incorrect.
Why it's wrong here
The API version '2024-02-15-preview' is valid.
- ✗
The endpoint URI is missing the resource name.
Why it's wrong here
The URI includes the resource name 'myfoundry'.
Go deeper
Related to this question
About these practice questions
Courseiva writes every AI-102 question from scratch — 945 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AI-102 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AI-102 exam.