← Blog

Claude API Vision: Image Analysis Example & Guide

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

What the Claude API vision feature actually does

Claude's vision capability lets you send an image alongside a text prompt and get back a text response describing, analyzing, or answering questions about that image. This works through the standard Messages API — there's no separate "vision endpoint." You attach an image as a content block in the same request where you'd normally send text, and Claude reads both together.

Practical use cases include reading charts and extracting the underlying data, transcribing handwritten or printed text (OCR-style tasks), describing product photos for e-commerce catalogs, flagging UI bugs from screenshots, classifying images by category, and comparing two or more images in a single request. Below are working examples you can adapt directly, plus the technical details that trip people up: supported formats, size limits, base64 encoding, and multi-image prompts.

Basic image analysis request structure

A vision request is a normal message with a content array that mixes an image block and a text block. The image block needs a source object specifying the media type and the base64-encoded data.

{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "base64",
            "media_type": "image/jpeg",
            "data": "<BASE64_ENCODED_IMAGE>"
          }
        },
        {
          "type": "text",
          "text": "What's shown in this image? Describe it in detail."
        }
      ]
    }
  ]
}

Supported media_type values are image/jpeg, image/png, image/gif, and image/webp. There's no URL-fetching option — you always send the raw bytes base64-encoded in the request body.

curl example: analyzing an image from disk

IMAGE_BASE64=$(base64 -w 0 product-photo.jpg)

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-20250514",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": "'"$IMAGE_BASE64"'"}},
          {"type": "text", "text": "List the product's visible defects, if any, and rate overall condition from 1-10."}
        ]
      }
    ]
  }'

On macOS, use base64 -i product-photo.jpg instead of -w 0, since the -w flag isn't available in BSD base64.

JavaScript example: reading an image file and sending it

import fs from "fs";
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

const imageData = fs.readFileSync("invoice-scan.png").toString("base64");

const response = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: [
        {
          type: "image",
          source: { type: "base64", media_type: "image/png", data: imageData },
        },
        {
          type: "text",
          text: "Extract the invoice number, total amount, and due date as JSON.",
        },
      ],
    },
  ],
});

console.log(response.content[0].text);

This pattern — image plus a structured extraction instruction — works well for OCR-adjacent tasks. Asking explicitly for JSON output in the text prompt makes the response easier to parse downstream, though Claude won't guarantee strict schema compliance without additional validation on your side.

Analyzing multiple images in one request

You can include several image blocks in the same content array, which is useful for comparisons, before/after analysis, or multi-page documents.

{
  "role": "user",
  "content": [
    {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": "<IMAGE_1>"}},
    {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": "<IMAGE_2>"}},
    {"type": "text", "text": "Compare these two screenshots and list every visual difference you can spot."}
  ]
}

Order matters: Claude processes images in the order they appear, and referring to "the first image" or "the second image" in your text prompt works reliably as long as you keep that order consistent.

Limits and practical constraints

A few things to plan around before building a production pipeline:

Wiring vision into a product without managing raw API keys

If you're building a feature on top of Claude's vision capability — a screenshot QA tool, a receipt scanner, a product catalog enricher — you'll eventually need usage tracking, per-customer API keys, and team access control, none of which the raw Anthropic API gives you out of the box.

SubToAPI wraps your existing Claude access into an HTTPS API with application-level keys (sub_live_...), streaming, and usage metadata, so you can issue a scoped key per customer or environment instead of sharing one root credential. The request shape for vision stays the same — you send the same image and text content blocks — just point your client at https://api.subtoapi.app/v1/messages with Authorization: Bearer $SUBTOAPI_KEY. See the quickstart and messages docs for the full request reference, or check pricing if you're evaluating plans — Solo starts at €9/month with a free trial at signup.

questions

Can Claude analyze images from a URL instead of base64? No. The Messages API only accepts base64-encoded image data in the request body — there's no option to pass an image URL and have Claude fetch it server-side. You need to download or generate the image bytes yourself and encode them before sending.

Which image formats does Claude's vision API support? JPEG, PNG, GIF, and WebP. If your source image is in another format (HEIC, BMP, TIFF), convert it to one of these before encoding, since unsupported media types will cause the request to fail.

Does analyzing larger images cost more tokens? Yes. Image token cost is based on pixel dimensions, not file size in megabytes. Downscaling images to roughly 1568px on the longest edge before sending typically cuts token usage significantly without degrading Claude's ability to read text or details in the image.

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 →