Hi all,
In my simple python code below, it happens run time error like below,
Error: 401 { "statusCode": 401, "message": "Unauthorized. Access token is missing,
invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired." }
import requests
# Azure OpenAI Configuration
API_KEY = "xxxxxx" # API key generated in Azure OpenAI
ENDPOINT = "https://xxxxx.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-02-15-preview" #Endpoint is copied from openAI
payload = {
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a joke."}
],
"temperature": 0.7,
"max_tokens": 100
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
}
# API call
response = requests.post(ENDPOINT, headers=headers, json=payload)
# print result
if response.status_code == 200:
print("Response:", response.json())
else:
print("Error:", response.status_code, response.text)
API key & End Point is copied from Azure OpenAI resource below,
and both key info

and the following model is created in SwedenCentral as Azure AI services,
and exists like below

I used copy/paste the each key and other necessary values, so it will be no problem.
Or my free trial subscription is the problem? Upgrade is needed?
Thanks!