← Blog

Claude API Vision: Image Analysis Tutorial

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

Claude's vision capability lets you send images alongside text in a single API request and get back a text response describing, classifying, or extracting data from that image. This tutorial walks through exactly how to structure those requests: encoding images correctly, building the content blocks Claude expects, and handling common cases like multiple images, screenshots, and charts.

If you've only used Claude for text so far, the vision workflow adds one extra step: your image has to be base64-encoded (or referenced by URL, depending on the client you use) and placed inside a content array next to your text prompt. Everything else — model selection, streaming, system prompts — works the same way you're already used to.

How Claude Vision Requests Are Structured

A vision-enabled message is just a regular messages API call where the content field is an array instead of a plain string. Each item in that array is either an image block or a text block. Claude processes them together as one multimodal prompt.

Here's the minimal shape:

{
  "model": "claude-sonnet-4-5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "base64",
            "media_type": "image/jpeg",
            "data": "<base64-encoded-image-data>"
          }
        },
        {
          "type": "text",
          "text": "What's shown in this image? Be specific about any text or numbers visible."
        }
      ]
    }
  ]
}

Supported image formats are JPEG, PNG, GIF, and WebP. There's a per-image size limit (around 5MB for most workflows), so large screenshots or high-res photos should be resized or compressed before encoding.

Step 1: Encode Your Image

In Node.js, reading a local file and base64-encoding it looks like this:

import fs from "fs";

const imageBuffer = fs.readFileSync("./chart.png");
const base64Image = imageBuffer.toString("base64");

If your image is already hosted somewhere public, some integrations accept a direct URL instead of base64 data — check your provider's docs, since not every endpoint supports URL-based sources.

Step 2: Send the Request with curl

Here's a full example using curl against a Claude-compatible endpoint. If you're calling the Anthropic API directly, you'd use your x-api-key header; if you're going through a wrapper service, you'd typically swap in a bearer token instead.

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": "'"$(base64 -i chart.png)"'"}},
        {"type": "text", "text": "Extract the data points from this bar chart as a JSON array."}
      ]
    }]
  }'

This pattern works well for extracting structured data from screenshots, invoices, receipts, or dashboards — Claude is good at reading embedded text and numbers accurately when the image resolution is reasonable.

Step 3: Multi-Image Prompts

You're not limited to one image per request. You can include several images in the same content array along with instructions on how to compare them:

const content = [
  { type: "image", source: { type: "base64", media_type: "image/jpeg", data: image1Base64 } },
  { type: "image", source: { type: "base64", media_type: "image/jpeg", data: image2Base64 } },
  { type: "text", text: "Compare these two UI screenshots and list every visual difference." }
];

This is useful for before/after comparisons, design review tooling, or QA pipelines that diff screenshots across app versions.

Using SubToAPI for Vision Requests

If you're already using SubToAPI to turn your Claude access into an HTTPS API, vision requests work through the same sub_live_... application keys and the same /v1/messages endpoint — no separate vision endpoint to learn. You build the content array exactly as shown above and send it with your standard bearer token:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -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": "'"$(base64 -i screenshot.png)"'"}},
        {"type": "text", "text": "Describe any accessibility issues visible in this UI."}
      ]
    }]
  }'

This is convenient if your team already has usage metadata, per-key rate limits, and seat management set up through SubToAPI for other Claude calls — vision requests show up in the same dashboard with the same billing and logging as everything else. See the messages docs for the full request schema, or the quickstart if you're setting this up for the first time.

Common Use Cases

Practical Tips

Questions

Does Claude support analyzing multiple images in one request? Yes. You can include several image blocks in the same content array alongside your text instructions, which works well for comparisons or multi-page documents.

What image formats and sizes does Claude vision accept? JPEG, PNG, GIF, and WebP are supported, with a per-image size limit around 5MB. Compressing or resizing large images before encoding avoids request failures.

Can I use Claude vision through SubToAPI the same way as text requests? Yes. Vision prompts go through the same /v1/messages endpoint and sub_live_... keys as text-only calls — see the docs or pricing to get started.

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 →