0

I would like to ask question from ChatGPT of Azure OpenAI

I have added Post URL. I have added Param "API_KEY" (key copied from Azure portal) I have added json body.

I get access denied. I suppose key must be correct. Could somebody send sample working API url?

    "error": {
        "code": "401",
        "message": "Access denied due to invalid subscription key       or wrong API endpoint. Make sure to provide a valid key for an active       subscription and use a correct regional API endpoint for your   resource."
    } 
}. 
Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
Kenny_I
  • 2,001
  • 5
  • 40
  • 94
  • 1
    I had the same error. In my case, I had a type in one of the headers. Had `api_key` instead of `api-key`. After fixing that, the query was successful. – ericOnline Mar 22 '23 at 19:29

1 Answers1

4

Setup your Postman request to make the following call. POST to Url: https://xxxx.openai.azure.com/openai/deployments/test/chat/completions?api-version=2023-03-15-preview This url you can get from the Azure portal in the General information section of the OpenAI Azure resource.

Set a header variable named api-key with the OpenAI key which you can get from the Azure portal in the Secrets section of the OpenAI Azure resource (not the Azure OpenAI portal)

Set the body as raw -> json with the following json

{
   "messages": [
   {
      "role": "user",
      "content": "how many faces does a cube have?"
    }
  ],
  "temperature": 0.7,
  "top_p": 0.95,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "max_tokens": 800,
  "stop": null
}

The key value pair named content is where you would ask your question. In this example the question is, "how many faces does a cube have?". The request response would similar to the following.

{
    "id": "chatcmpl-xxxx",
    "object": "chat.completion",
    "created": 1683143567,
    "model": "gpt-35-turbo",
    "choices": [
        {
            "index": 0,
            "finish_reason": "stop",
            "message": {
                "role": "assistant",
                "content": "A cube has six faces."
            }
        }
    ],
    "usage": {
        "completion_tokens": 6,
        "prompt_tokens": 16,
        "total_tokens": 22
    }
}

This example is just to get the Postman request working and without securing the endpoint.