Base64 Image Too Large for a Vision API
If a vision API rejects your image as too large (or a 413), the fix is to shrink it before encoding: resize the dimensions and re-encode as JPEG. Base64 also adds ~33% overhead. Drop an image below to see its size against each provider's limit and download a smaller version — all in your browser.
How to fix a "base64 image too large" error
The error means the image exceeds the provider's per-image limit, or the full request exceeds its payload limit (that's the 413 "payload too large"). You cannot fix it by editing the Base64 string — you have to make the underlying image smaller and re-encode it. Two levers do almost all the work:
- Resize the dimensions. Scale the longest side down to 1024–1536 px. Pixels are the dominant cost, so this is the biggest win.
- Re-encode as JPEG. A screenshot saved as PNG can be many times larger than the same image as JPEG at quality 0.85. Unless you need transparency, JPEG wins.
Do both, then Base64-encode the result. The resizer above runs the whole pipeline — resize on a canvas, re-encode with canvas.toBlob('image/jpeg', quality), and hand you the new Base64 and a downloadable file.
Per-provider image size limits
Encoding to Base64 counts against these limits, because the encoded string is what actually travels in the request body. Approximate current limits:
| Provider | Limit | Notes |
|---|---|---|
| OpenAI (GPT-4o / GPT-4.1) | ~5 MB per image | Auto-downscales large images; caps effective resolution (short side ≤ 768 px in detail tiles). |
| Anthropic Claude | ~5 MB per image | Auto-resizes images whose long edge exceeds ~1568 px, so bigger uploads gain nothing. |
| Google Gemini | ~20 MB total inline request | Above this, upload via the Files API and pass a file reference instead of inline Base64. |
Because OpenAI and Claude downscale anyway, sending a huge image just wastes upload bandwidth and risks the limit for no accuracy gain.
Why base64 makes it worse (~33%)
Base64 encodes every 3 bytes of binary as 4 ASCII characters, so the encoded text is about 33% larger than the original file. A 4 MB image becomes roughly 5.3 MB of Base64. That's exactly enough to push an "almost fits" image over a 5 MB per-image limit. The original panel above shows both numbers so you can see the gap. For the underlying math, see the Base64 size calculator.
Resize before you encode
Dimensions matter more than the Base64 overhead for both size and token cost. Vision models split an image into tiles and bill tokens per tile, so a 4000 px photo costs far more tokens than the same scene at 1024 px — often with no extra useful detail, since the model downscales it regardless. Resize first, then encode. For a longest side of 1024–1536 px at JPEG quality 0.8–0.9, most images drop by 70–95% and comfortably clear every provider limit.
Is this private?
Yes. The resize and re-encode happen locally on a <canvas> in your browser, and the Base64 is produced in memory — nothing is uploaded. You can confirm in DevTools → Network: resizing fires no request. The only network call on this page is anonymous page-view analytics.
Frequently asked questions
Why is my base64 image too large for the API?
The image's file size exceeds the provider's per-image limit, or the whole request exceeds its payload limit and you get a 413. Base64 adds ~33% overhead, so a photo that looks under the limit as a file can still push the encoded request over it. Resize the dimensions and re-encode as JPEG to fix it.
What's the max image size for GPT-4o / Claude / Gemini?
OpenAI (GPT-4o / GPT-4.1) and Anthropic Claude both accept roughly 5 MB per image and auto-downscale large ones. Google Gemini allows about 20 MB for the total inline request; beyond that, use its Files API instead of inline Base64.
Does base64 increase the image size?
Yes — by about 33%. Base64 turns 3 bytes into 4 ASCII characters, so a 3 MB image becomes roughly 4 MB of text. That encoded size is what counts against the API's limit.
How do I reduce a base64 image's size?
Don't touch the Base64 string directly — shrink the image. Resize the longest side to 1024–1536 px and re-encode as JPEG at quality 0.8–0.9, then encode. Use the resizer above; it typically cuts size by 70–95% and gives you the smaller Base64.
Will resizing hurt the model's accuracy?
Usually not. Vision models tile and downscale images internally, so a longest side of 1024–1536 px is plenty for most documents, screenshots, and photos. Only push higher for dense text or fine detail.
Need text, files, or URL-safe Base64?
The main base64.dev tool handles text, files, and URL-safe mode with auto-detect.
Open base64.dev →