PSA - gpt-4-vision accidental high token usage

Public Service Announcement

I had ChatGPT Plus whip up a python script to use gpt-4-vision-preview. It had some outdated information, and so I told it was wrong and to search with bing to get the updated info. Script looked good but I’m not a python dev so I didn’t examine it thoroughly. I had 4 requests and got billed for 90k tokens, and by math with ~100 token text prompt, and a 512x512 image, I should have been billed for 4 x ~185 tokens.

Well, apparently ChatGPT Plus goofed and encoded the base64 image as content and not as an image url, so I got billed for a stupid number of tokens. Thank God for rate limiting.

#messages=[{"role": "system", "content": "<my text prompt>"},
#          {"role": "user", "content": image_base64}],

# Use this instead
messages=[{"role": "user", "content": [
            "type": "image_url",
            "image_url": {
                "url": f"data:image/jpeg;base64,{image_base64}"
            "type": "text",
            "text": "<my text prompt>"

Hi and welcome to the Developer Forum!

Just an Idea, I think it would be good to also post the code you ended up using after you fixed it :grin:

1 Like

Hi Fox… I did. I just put it all in one block, and commented out the bad version and left a comment on both which was bad and good. :slight_smile:

1 Like

Thanks for the clarification, yes I missed that! Cheers.

Hello, pretty sure I have my form right, but it’s also giving me stop reason length/seems to be counting the encoded string as text.

Mind taking a look?

[{‘role’: ‘system’, ‘content’: [{‘type’: ‘text’, ‘text’: 'You are a brilliant expert in aircraft engineering. '}]}, {‘content’: [{‘type’: ‘text’, ‘text’: ‘What is in this picture?’}, {‘image_url’: {‘url’: ‘data:image/jpeg;base64,/9j/4AAQSkZ…pTsZ6UANAyaeFzTgnGKmVMcmlcBVXjmn/SgUUggigAooooA/9k=’}, ‘type’: ‘image_url’}], ‘role’: ‘user’}]