Claude API Image Vision Input Guide
Claude's vision-capable models accept images directly in the API request alongside text, letting you build apps that read charts, extract text from screenshots, describe photos, or analyze diagrams. This guide covers exactly how to structure those requests: the message format, image encoding options, size limits, and common mistakes that cause failed or low-quality responses.
If you've only used Claude for text, the key thing to understand is that images aren't a separate endpoint — they're a content block type inside the same messages array you already use for text. You mix text and image blocks in whatever order makes sense for your prompt, and Claude processes them together as one request.
How image input works in the Claude API
A standard text-only message looks like this:
{"role": "user", "content": "What's in this invoice?"}
For vision, content becomes an array of blocks, where one or more blocks are type image and at least one is usually type text with your instructions:
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "<base64-encoded-image-data>"
}
},
{
"type": "text",
"text": "Extract the total amount and due date from this invoice."
}
]
}
Claude supports image/jpeg, image/png, image/gif, and image/webp. The model reads the image and the text together, so ordering images before the related question usually produces better results than putting text first.
Encoding images as base64
Most implementations send images as base64 strings. In Node.js:
import fs from "fs";
const imageData = fs.readFileSync("./receipt.png").toString("base64");
const payload = {
model: "claude-sonnet-4",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "image",
source: {
type: "base64",
media_type: "image/png",
data: imageData,
},
},
{ type: "text", text: "List every line item and its price." },
],
},
],
};
If you're routing requests through SubToAPI instead of managing raw Claude credentials, the request body is identical — you just send it to https://api.subtoapi.app/v1/messages with your sub_live_... key:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "'"$(base64 -i receipt.png)"'"}},
{"type": "text", "text": "List every line item and its price."}
]
}]
}'
Full request/response details are in the messages docs, and the quickstart walks through getting an API key if you're starting from scratch.
Sending multiple images
You can include several images in one message — useful for comparing two screenshots, analyzing a multi-page scan, or asking Claude to spot differences between before/after shots. Just add more image blocks:
{
"role": "user",
"content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "<image1>"}},
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "<image2>"}},
{"type": "text", "text": "What changed between these two dashboard screenshots?"}
]
}
Label images in your text prompt ("the first image shows X, the second shows Y") when the distinction matters, especially past three or four images in one request.
Image size and token considerations
Images consume tokens just like text, and larger or higher-resolution images cost more. A few practical rules:
- Resize before sending. Claude doesn't need print-resolution images to read text or describe content accurately. Resizing to around 1500px on the longest edge is usually enough and reduces both payload size and token cost.
- Max file size per image is capped (check current limits in the API docs for your plan), so compress large screenshots or photos before base64-encoding them.
- Base64 inflates payload size by roughly 33%, so a 2MB image becomes a ~2.7MB request body. Keep this in mind if you're hitting request size limits.
- Crop to the relevant area when you only need Claude to read one section of a larger image — it improves accuracy and cuts token usage.
Common mistakes to avoid
- Wrong
media_type. If your file is a PNG but you label itimage/jpeg, the request may fail or Claude may misread the content. Match the declared type to the actual file. - Forgetting the text block. Sending an image with no instruction text often gets a generic description instead of the specific extraction or analysis you wanted. Always pair images with a clear text prompt.
- Sending non-base64 raw bytes. The
datafield must be a base64-encoded string, not raw binary or a file path. - Expecting bounding boxes or pixel coordinates. Claude can describe and reason about image content but isn't designed as a precision object-detection system — don't rely on it for exact pixel coordinates.
- Not handling streaming with images. If you're using streaming responses for vision requests, the setup is the same as text-only streaming — see the streaming docs for the event format.
Where vision input fits in a real app
Common use cases worth building around: receipt and invoice parsing, UI bug triage from screenshots, chart/graph reading for data pipelines, ID or document verification flows, and accessibility tools that describe images for users. In all of these, the pattern is the same — encode the image, attach a clear instruction, and parse Claude's text response into whatever structure your app needs.
If you're prototyping quickly and don't want to manage separate API credentials, model routing, or usage tracking for a vision feature, SubToAPI gives you a single HTTPS endpoint with an application key, so you can ship the feature and worry about auth and billing later. Check pricing if you're evaluating options for a team.
questions
Does Claude support image URLs instead of base64? The standard and most reliable method is base64-encoded data in the source field. If your images live remotely, download them server-side and encode them before sending the request rather than passing a raw URL.
Can Claude read handwritten text in images? Yes, with varying accuracy depending on legibility. Clear handwriting is usually read correctly; messy or stylized handwriting may produce errors, so always validate extracted text for critical use cases.
Do vision requests cost more than text-only requests? Images are converted into tokens based on size and resolution, so a vision request typically uses more tokens than an equivalent text-only prompt. Resizing images before sending helps keep costs predictable.