0

I am trying steps from this tutorial - https://github.com/Azure-Samples/openai/blob/cf0f19f36a30925e3891137b0bc2539e25687cac/Basic_Samples/AAD_Integration/setup_aad.md

I tried to run the completion from Azure CLI. I notice that if I use authorisation header in curl api then the call fails. However, if I use api-key header then the call works. What is the difference?

with authorisation header

PS /home/manu> curl ${OPENAI_API_BASE}/openai/deployments/try-davinci/completions?api-version=2022-12-01 -H "Content-Type: application/json" -H "Authorization: Bearer $accessToken" -d '{ "prompt": "Tell me a funny story." }'             
{"error":{"code":"PermissionDenied","message": "Principal does not have access to API/Operation."}}

with api-key header

PS /home/manu> curl https://aoai-try-mc.openai.azure.com/openai/deployments/try-davinci/completions?api-version=2022-12-01 -H "Content-Type:application/json" -H "api-key:keygoeshere" -d '{"prompt":"Tell me a funny story"}'
{"id":"cmpl-7MWgCWwibSp1nToOLeDfW7VkJvY8T","object":"text_completion","created":1685603192,"model":"text-davinci-003","choices":[{"text":"\n\nOnce, a chicken and a pig were talking and the chicken said,","index":0,"finish_reason":"length","logprobs":null}],"usage":{"completion_tokens":16,"prompt_tokens":5,"total_tokens":21}}
Manu Chadha
  • 15,555
  • 19
  • 91
  • 184
  • 1
    `Principal does not have access to API/Operation.` - Error message indicates that you do not have proper RBAC role assigned to the user making the request. Please assign `Cognitive Services User` RBAC role to the user making the request and retry the operation. – Gaurav Mantri Jun 01 '23 at 09:37

1 Answers1

0

{"error":{"code":"PermissionDenied","message": "Principal does not have access to API/Operation."}}

Initially, I got the same error in my environment when I tried with the authorisation header.

enter image description here

I agree with Gaurav Mantri's comment, the error suggests that do not have a proper RBAC role assigned to the user making the request.

After assigning Cognitive Services User RBAC role assigned to the user it worked perfectly.

enter image description here

Command:

export OPENAI_API_BASE="your-endpoint-name"
az login
export accessToken=$(az account get-access-token --resource https://cognitiveservices.azure.com | jq -r .accessToken)
curl ${OPENAI_API_BASE%/}/openai/deployments/sample1/completions?api-version=2022-06-01-preview -H "Content-Type: application/json" -H "Authorization: Bearer $accessToken" -d '{ "prompt": "Tell me a funny story." }'

Output:

{"id":"cmpl-7P303xXofAOwxxxxx","object":"text_completion","created":168620xx,"model":"text-davinci-002","choices":[{"text":"\n\n\nOne day, a chicken and a duck were walking together when they came","index":0,"finish_reason":"length","logprobs":null}],"usage":{"completion_tokens":16,"prompt_tokens":6,"total_tokens":22}}

enter image description here

Venkatesan
  • 3,748
  • 1
  • 3
  • 15