java.io.IOException: Server returned HTTP response code: 400

While the binary file you send may be large, as long as you use the proper “content” message format to send it, it will only count for between 85 - 1445 tokens depending on the quality and size you specify.

If you made a mistake and sent garbage text that was too long, the API would return a different error, that you exceeded the model’s context length or your usage limit, both with the message having a token count.

Here’s a link to a post showing how the body of a message should be sent for base64.

I’ll let you decipher what your code is doing between all the escaping.