You can compare a working solution to what you offered with poor indents and actual use of a f-string for setting headers:
import requests
import os
# Get the API key from the environment
# or use a hard-coded fallback if not available
api_key = os.getenv("OPENAI_API_KEY", "sk-12345-key")
imgLink = "https://benny-image-shop.s3.ap-south-1.amazonaws.com/2024-05-01/1714564843256000_152.58.111.108.jpg"
payload = {
"model": "gpt-4-turbo",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "describe"},
{"type": "image_url", "image_url": {"url": imgLink, "detail": "low"}},
],
}
],
"max_tokens": 500,
}
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
response = requests.post(
"https://api.openai.com/v1/chat/completions", headers=headers, json=payload
)
# Print the response to see what the API returns
print(response.text)
detail:low
will cut the cost of your experimentation significantly (which you probably figured out and got working by now).