GPT-4-Turbo API giving error with valid image

I am getting an error msg with the gpt-4-turbo, for describing an image that I am sending through URL in the API. The image size is 6.9 MB, and the max allowed limit is 20 MB.

Code -

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
                }
            }
            ]
        }
        ],
        "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)

Error - {‘error’: {‘message’: ‘Invalid image.’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

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).