ChatGPT does not accept my image

Hi,
i have seen a similar request here already but i dont find the problem.


def analyze_screenshot_base64(encoded_image):
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {openai.api_key}"
    }

    payload = {
        "model": "gpt-4o-mini",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "Develop a trading setup (LONG or SHORT) with a CRV of at least 5 based on this chart. Include entry price, stop loss, and take profit levels."
                    },
                    {
                        "type": "image_url",
                        "image": {
                            "url": f"data:image/png;base64,{encoded_image}"
                        }
                    }
                ]
            }
        ],
        "max_tokens": 300
    }

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

Thats my python request but the api returns me:

{‘error’: {‘message’: ‘Invalid content type. image_url is only supported by certain models.’, ‘type’: ‘invalid_request_error’, ‘param’: ‘messages.[0].content.[1].type’, ‘code’: None}}

Honestly i have no idea any more what it could be - but i am not a good coder :slight_smile:

Welcome to the dev forum @ploetzeneder

Here’s the error in your code:

Here’s how the correct image_url content block looks like:

{
          "type": "image_url",
          "image_url": {
            "url": f"data:image/jpeg;base64,{base64_image}"
          }
2 Likes

Insane ! What a silly mistake thx a lot!