Home → Help

Image input rejected by a vision model

Either the base64 payload is missing its data URL prefix, the encoding picked up newlines, the file is over the size limit, or the format is one the model does not accept. The error text rarely distinguishes them.

What you are seeing

Why it happens

A base64 image sent as image_url needs the full data URL, including the media type: data:image/png;base64,. Sending the bare payload is the single most common cause.

Command-line base64 wraps lines by default on many systems. The embedded newlines make the payload invalid even though it looks right. Use the flag that disables wrapping.

Size limits apply to the encoded payload, which is about a third larger than the file on disk. An image just under the limit locally can be over it on the wire.

Confirm it is this

Encode without line wrapping and confirm the prefix is present:

b64=$(base64 -w0 image.png)      # macOS: base64 -i image.png | tr -d '\n'
echo "payload bytes: ${#b64}"
printf 'data:image/png;base64,%s' "$b64" | head -c 40; echo

The first 40 characters should start with data:image/png;base64,. If your payload bytes are far larger than expected, the file itself is too big.

How to fix it

  1. Send the full data URLInclude the scheme and media type. A PNG sent with an image/jpeg media type is also rejected by some models, so match it to the real format.
  2. Disable line wrapping when encodingbase64 -w0 on Linux, or pipe through tr -d to strip newlines on macOS.
  3. Resize before sendingMost vision models downscale internally anyway. Sending a 12-megapixel photo costs you upload time and tokens without improving the answer.
Image input is billed as input tokens on APICLAN, and larger images cost more because they become more tokens. Resizing before the call is a direct saving, not just a way around the limit.

Related

Unexpected token '<' when calling an OpenAI-compatible API401 invalid API key — when the key looks right but still fails

Last checked 2026-10-01. Written from problems diagnosed on a live OpenAI-compatible gateway, not collected from other sites.