401 Unauthorized Error in Azure OpenAI Deployment (GPT-4o-mini)

Bình Đỗ 20 Reputation points
2025-02-20T08:16:29.57+00:00

We are currently facing authentication issues while deploying GPT-4o-mini on Azure OpenAI. Here are the details of the errors encountered:

1) Issue 1: API Call Failure with 401 Unauthorized

  • When making a request to the OpenAI deployment endpoint, we receive the following error: Client error: POST https://it-m7cq0ja0-eastus2.cognitiveservices.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-08-01-preview resulted in a 401 Unauthorized

2) Issue 2: Access Token Issue

We have obtained two API keys for GPT-4o-mini. However, when testing the model, authentication failed: "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or has expired."

The team is sure that: API keys were correctly copied and used in the Authorization Bearer Token, and endpoint matches our Azure OpenAI deployment region.

Any guidance would be greatly appreciated. Thank you in advance! 🚀

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,709 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. santoshkc 12,505 Reputation points Microsoft Vendor
    2025-02-21T15:10:53.9233333+00:00

    Hi @Bình Đỗ,

    We have tested the scenario and were able to make successful API calls without encountering the 401 Unauthorized error. The request returned a 200 OK response, confirming that the API key and endpoint were correctly configured.

    To help resolve your issue, please check the following:

    1. API Key Usage – Ensure you're passing the key as api-key: <your-api-key> in the header and not using Authorization: Bearer <token>.
    2. Correct Endpoint – Verify that your request URL matches the exact format for your Azure OpenAI deployment, including the correct region.
    3. Access Control – Confirm that your Azure user has the Azure OpenAI User role assigned in IAM.
    4. Regenerate API Key – If the issue persists, try regenerating the API key and testing again.

    User's image

    If you've checked these and are still facing issues, please share the exact error message and request details (excluding sensitive information) so we can assist further.

    I hope you understand. Thank you.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.