Image to Base64 for API calls
Convert an image to Base64 and paste it straight into your API request. This page outputs the exact payload shapes that OpenAI vision models and Google Cloud Vision expect — no guesswork about prefixes, no hosting, no upload.
100% client-side. Sensitive images never leave your device.
Drop an image to build your API payload
or paste from your clipboard · everything stays in your browser
The two payload shapes every vision API uses
Multimodal APIs accept images in one of two shapes, and mixing them up is the most common reason a
Base64 image comes back broken. OpenAI (GPT-4o, GPT-4.1 and the other vision-capable
models) wants a content part with type: "image_url" whose image_url.url
is the full data URI — prefix and all:
{
"model": "gpt-4o",
"messages": [{
"role": "user",
"content": [
{ "type": "text", "text": "Describe this image" },
{ "type": "image_url",
"image_url": { "url": "data:image/png;base64,iVBORw0KGgo..." } }
]
}]
}
Google Cloud Vision is the opposite: the image.content field takes the
raw Base64 payload only — a data: prefix there causes an encoding error:
{
"requests": [{
"image": { "content": "iVBORw0KGgo..." },
"features": [{ "type": "TEXT_DETECTION" }]
}]
}
This page reads your image once and fills both templates for you, with the correct MIME type detected
from the actual file — PNG, JPEG, WebP, GIF and SVG all get their proper data:image/…
prefix automatically.
Step by step
- Add the image. Drag it in, pick it, or paste from the clipboard.
- Copy the payload for your API. OpenAI and Cloud Vision templates are filled in automatically; the full data URI and raw Base64 outputs cover every other API.
- Send it. The payload is valid JSON with the image already escaped — no manual string assembly, no truncation.
Mind the request size
Base64 inflates bytes by about 33%, and vision APIs cap request bodies (typically 4-20 MB). A phone photo at 4 MB becomes a 5.3 MB string before you have added a single prompt token. Models rarely benefit from more than 1024-2048 px of input, so compress the image first — resize to the resolution the model actually sees and the payload shrinks by an order of magnitude.
Why in-browser conversion matters for API work
Vision pipelines often handle images that cannot be pasted into a random web tool: internal
screenshots, unreleased product photos, medical scans, documents under NDA. Upload-based converters
put those bytes on someone else's server. This page encodes with the browser's
FileReader API instead — there is no upload step at all, which you can verify in the
Network tab: converting fires zero requests.
Debugging payloads that come back the other way
Many APIs also return images as Base64 inside JSON. When one does, the Base64 to image decoder previews and saves it, and the data URI extractor pulls every embedded image out of a bulk JSON or CSS dump in one pass.
More Base64 converters
Frequently asked questions
How do I send an image to the OpenAI API as Base64?
Use an image_url content part whose URL is the full data URI — data:image/png;base64,YOUR_STRING. Vision models such as GPT-4o and GPT-4.1 accept data URIs directly, so no hosting or multipart upload is needed.
How do I send an image to Google Cloud Vision as Base64?
Put the raw Base64 string (no data: prefix) in the image.content field of the annotate request. This page outputs both forms so you can paste whichever the API expects.
How large can a Base64 image be in an API request?
Request bodies are typically capped between 4 MB and 20 MB depending on the API, and Base64 adds about 33%. Resize to what the model actually sees — the compressor handles it in one step.
Is it safe to convert sensitive images here?
Yes. The image is read and encoded entirely in your browser with the FileReader API. Nothing is uploaded, so NDA'd screenshots and internal documents never leave your device.
Why does my Base64 image show up broken in the API response?
Usually a truncated copy, a missing or doubled data: prefix, or hand-rolled JSON escaping. Pasting the payload straight from this tool avoids all three.
Which other APIs accept Base64 images?
Most do, in one of the two shapes above: full data URI (OpenAI, Anthropic's source.data) or raw payload (Cloud Vision, most self-hosted model servers). When in doubt, the API's error message will name the field it rejected.