← Blog

Claude API Image Vision Input Guide

2026-11-23 · 5 min read · SubToAPI Team

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:

Common mistakes to avoid

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.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →