Claude API Image Analysis: Vision API Guide
How image analysis works with the Claude API
Claude's vision capability lets you send images alongside text in a single API request and get back a text response describing, extracting, or reasoning about what's in the image. You don't need a separate vision endpoint — image analysis runs through the same messages API you use for text, with the image passed as base64-encoded content or a URL inside the message body.
This covers the most common use cases developers search for: reading text out of screenshots (OCR-style extraction), describing charts and graphs, analyzing UI mockups, classifying photos, comparing two images, and pulling structured data out of scanned documents. Claude handles multiple images in one request, so you can ask it to compare a "before" and "after" screenshot or cross-reference a chart against a table in the same call.
Sending an image to the Claude API
The core pattern is a messages request where the content array mixes an image block with a text block. Images are typically base64-encoded JPEG, PNG, GIF, or WebP, capped at a few megabytes depending on the provider you're using.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgA..."
}
},
{
"type": "text",
"text": "What error message is shown in this screenshot, and what line of code is it pointing to?"
}
]
}
]
}'
The response comes back as a normal text message — no special parsing required. This is what makes vision useful for production features like "attach a screenshot to your support ticket and get an automatic summary" or "upload a receipt and extract the total."
Encoding images in JavaScript
Most of the work in a real integration is getting the image into base64 correctly, not calling the API itself.
import fs from "fs";
function imageToBase64(path) {
return fs.readFileSync(path).toString("base64");
}
async function analyzeImage(path, question) {
const base64Image = imageToBase64(path);
const response = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"x-api-key": process.env.ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
},
body: JSON.stringify({
model: "claude-sonnet-4-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "image",
source: {
type: "base64",
media_type: "image/jpeg",
data: base64Image,
},
},
{ type: "text", text: question },
],
},
],
}),
});
const data = await response.json();
return data.content[0].text;
}
In the browser, you'd swap fs.readFileSync for a FileReader reading a File object from an <input type="file">, then strip the data:image/...;base64, prefix before sending.
Practical use cases worth knowing
Document and invoice extraction. Send a photo or scan of an invoice and ask Claude to return structured JSON with vendor, line items, and totals. This works well as a pre-processing step before storing data in a database — just be explicit in your prompt about the exact field names and format you want back.
Chart and dashboard reading. Claude can describe trends in a line chart or read values off a bar chart image, which is useful for automated reporting tools that need to summarize a screenshot of an analytics dashboard in plain language.
UI and design review. Feeding in a mockup or a live screenshot and asking "does this layout follow our spacing guidelines" or "what accessibility issues do you see" is a common workflow for design QA.
Multi-image comparison. You can include two or more image blocks in the same content array and ask Claude to compare them — spot differences between two screenshots, check if a rendered page matches a design file, or verify before/after states in a visual regression test.
Cost and latency considerations
Images consume tokens just like text — roughly proportional to resolution, so a high-resolution photo costs noticeably more than a compressed screenshot. If you're analyzing the same type of image repeatedly (e.g., invoices from one vendor), resizing images down to a reasonable resolution before sending them cuts both cost and latency without hurting accuracy for text-heavy content.
Latency for vision requests is slightly higher than pure text requests of similar token count, so if your product shows a loading state, plan for that.
Running vision requests through SubToAPI
If your team is already using Claude through a shared subscription rather than direct API billing, you can still build image analysis features without duct-taping credentials together. SubToAPI turns your existing Claude access into a standard HTTPS API with sub_live_... application keys, so the same messages-with-image pattern shown above works unchanged — just point requests at https://api.subtoapi.app/v1/messages and authenticate with Authorization: Bearer $SUBTOAPI_KEY instead of calling Anthropic directly.
This is particularly useful for teams who want usage metadata per API key (so you can see which internal tool or client is generating vision traffic) or who need multiple engineers working under one subscription with separate keys and seats instead of sharing a single login. Streaming and tool use work the same way as text requests too — see the quickstart, messages docs, and streaming guide for the full request shapes. Plans start at €9/month for solo use, with team and scale tiers at €19 and €49 per seat — details on pricing, and you can try it with a free trial at signup.
questions
Does Claude's vision API support PDFs directly, or only images? The image content type accepts JPEG, PNG, GIF, and WebP. For PDFs, you typically convert pages to images first or use a document-specific endpoint if your provider offers one, then send each page as a separate image block.
How many images can I send in one request? You can include multiple image blocks in a single content array. Practical limits come from total payload size and token budget rather than a hard count — keep requests to a handful of images for best latency and reliability.
Is image analysis accuracy good enough for OCR-style text extraction? Yes for most typed and reasonably clean handwritten text, especially screenshots, scanned forms, and receipts. Accuracy drops with very low resolution, heavy skew, or dense small print, so preprocessing (cropping, contrast boost) helps.