Unable to Perform HTTP Communication with Azure OpenAI Service - Request Assistance

sahashi 20 Reputation points
2024-11-11T12:46:20.66+00:00

Dear Azure Support Team,

I am experiencing an issue while attempting to perform HTTP communication using the Azure OpenAI Service.

Error Message: 401 Unauthorized "Access denied due to invalid subscription key or wrong API endpoint."

Details of Confirmed Items

API Key

I have tried both Key 1 and Key 2 obtained from the "Keys and Endpoints" section of the Azure portal.

Endpoint

  I am using the endpoint confirmed in the Azure portal (e.g., `https://
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Fang 1,060 Reputation points MVP
    2024-11-12T03:56:39.8366667+00:00

    Hi @sahashi

    the error message you shared normally indicates the subscription key is incorrect. you can use below example CURL call to test out in bash. Change the endpoint url, deployment name and api key to your own.

    curl -i --location 'https://<your-instance>.openai.azure.com/openai/deployments/<deployment>/chat/completions?api-version=2024-08-01-preview' \
    --header 'Content-Type: application/json' \
    --header 'api-key: xxxxx' \
    --data '{
        "messages": [
            {
                "role": "system",
                "content": [
                    {
                        "type": "text",
                        "text": "You are a helpful assistant who talks like a pirate."
                    }
                ]
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "Good day, who am I talking to?"
                    }
                ]
            },
            {
                "role": "assistant",
                "content": [
                    {
                        "type": "text",
                        "text": "Ahoy there, matey! What be bringin ye to these waters today? "
                    }
                ]
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "Where is the treasure island?"
                    }
                ]
            }
        ],
        "temperature": 0.7,
        "top_p": 0.95,
        "max_tokens": 800
    }'
    
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Avinash Devarakonda 610 Reputation points Microsoft External Staff
    2024-11-12T07:28:53.07+00:00

    Hi @sahashi,

    Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    The “401 Unauthorized” error typically indicates a problem with the subscription key or the endpoint. Here are a few steps to help resolve this:

    1. Ensure that the subscription key you are using is correct and has not expired.
    2. Confirm that the endpoint URL you are using matches the one provided in the “Keys and Endpoints” section of your Azure OpenAI resource.
    3. Verify that your API key has the necessary permissions to access the endpoint.
    4. If you’ve checked all these and the issue persists, it might be helpful to regenerate the keys and update your application with the new keys. Additionally, you can refer to the Azure API Management Troubleshooting Guide

    Hope this helps. Do let us know if you any further queries.


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

    Thank You.


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.