API cannot identify character in image whilst chatgpt.com can

Hi. I sent an image to both the API and the chatgpt website. The website identifies the character in my image flawlessly whilst through the API it fails to identify the character at all. It still analyzes the image etc. but will not recognize the character. Models are the same.

Hi and welcome to the developer forum!

Can you post your API calling code here please, also the version of the OpenAI API library you are using.

Its the same as the example on the API site

def chatgpt_analyze_img(img_path, query):

base64_image = encode_image(img_path)

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {chatgpt_key}"
}

payload = {
"model": "chatgpt-4o-latest",
"messages": [
    {
    "role": "user",
    "content": [
        {
        "type": "text",
        "text": f"{query}"
        },
        {
        "type": "image_url",
        "image_url": {
            "url": f"data:image/jpeg;base64,{base64_image}"
        }
        }
    ]
    }
],
"max_tokens": 300
}

response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)

return response.json().get('choices')[0].get('message').get('content')

There is a parameter setting for the image quality. Set it to High (default is Auto)

1 Like

I am sorry but the model name seems off. What does ‘chatgpt-4o-latest’ points to? GPT-4o?

Welcome to the dev forum @emolk

It works both in ChatGPT and API for me.