Home / Docs / Vision and image input

Vision and image input

Send images to multimodal models — encoding, size limits, and what it costs.

Claude and Gemini models accept images alongside text. Images are content blocks inside an ordinary message.

Base64 image

{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "messages": [{
    "role": "user",
    "content": [
      {"type": "image", "source": {
        "type": "base64",
        "media_type": "image/png",
        "data": "iVBORw0KGgoAAAANSUhEUg..."
      }},
      {"type": "text", "text": "What does this chart show?"}
    ]
  }]
}

Python

import base64, anthropic

img = base64.standard_b64encode(open(class="s">"chart.png", class="s">"rb").read()).decode()

client = anthropic.Anthropic(api_key=class="s">"sk-your-key", base_url=class="s">"https://aiprimetech.io")
msg = client.messages.create(
    model=class="s">"claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{class="s">"role": class="s">"user", class="s">"content": [
        {class="s">"type": class="s">"image", class="s">"source": {class="s">"type": class="s">"base64",
         class="s">"media_type": class="s">"image/png", class="s">"data": img}},
        {class="s">"type": class="s">"text", class="s">"text": class="s">"What does this chart show?"},
    ]}],
)
print(msg.content[0].text)

Practical limits

ConstraintGuidance
FormatsPNG, JPEG, GIF and WebP
ResolutionVery large images are downscaled upstream. Resizing to roughly 1500px on the long edge before sending saves tokens with no quality loss.
CostImages bill as input tokens, roughly proportional to area. A full-page screenshot can cost more than a page of text.
Multiple imagesSeveral image blocks per message are allowed; each one is billed.
In an agent loop, images are resent with the history on every turn like any other content. Drop them from the transcript once they have been described, or one screenshot gets paid for repeatedly.