Hello @nam seungwoo ,
Looks like you're trying to response from a chat completion 4o model. When calling a chat completion you can use:
- API Key Authentication: You include the API key in the
api-key
HTTP header for each request. - Microsoft Entra ID Authentication: You use a Microsoft Entra token, included in the
Authorization
header asBearer YOUR_AUTH_TOKEN.
In the code below you're combining the two. If you want to use the API key in your screenshot switch your header to "api-key":API_KEY. If you want to use Microsoft Entra ID Authentication you'll need to do some additional configuration.
Below is from a working chat.completions request:
import os
import requests
import base64
# Configuration
API_KEY = "YOUR_API_KEY"
IMAGE_PATH = "YOUR_IMAGE_PATH"
encoded_image = base64.b64encode(open(IMAGE_PATH, 'rb').read()).decode('ascii')
headers = { "Content-Type": "application/json", "api-key": API_KEY, }
# Payload for the request
payload = { "messages": [ { "role": "system", "content": [ { "type": "text", "text": "You are an AI assistant that helps people find information." } ] } ], "temperature": 0.7, "top_p": 0.95, "max_tokens": 800 }
ENDPOINT = "https://aiestimator.openai.azure.com/openai/deployments/AIEstimator/chat/completions?api-version=2024-02-15-preview"
# Send request
try: response = requests.post(ENDPOINT, headers=headers, json=payload)
***To ensure the security of your applications and data, never share your API keys with anyone.