匠人学院 JR Academy
Skip to article
Learning guide
Claude API Guide

Build with the Claude API for messages, streaming, multimodal input, and production integrations.

3 chapters·9 guides·Access varies by chapter
Vision
On this page

Image Input with Claude

Vision input is useful for explaining a diagram, extracting visible fields or reviewing a screenshot. It can miss small text, misread a chart or infer details that the image does not support.

#Send a local image

The following Python example requires the anthropic package, an authorized API account, ANTHROPIC_MODEL and a local diagram.png. Running it sends image data to the provider and may incur charges.

python
import base64 import os from pathlib import Path from anthropic import Anthropic encoded = base64.b64encode(Path("diagram.png").read_bytes()).decode("ascii") response = Anthropic().messages.create( model=os.environ["ANTHROPIC_MODEL"], max_tokens=512, messages=[{"role": "user", "content": [ {"type": "image", "source": { "type": "base64", "media_type": "image/png", "data": encoded }}, {"type": "text", "text": ( "Describe the components and arrows in this diagram. " "Mark unreadable labels as unreadable; do not guess." )}, ]}], ) for block in response.content: if block.type == "text": print(block.text)

The MIME type must match the actual file. Check current supported formats, request size and image-count limits before building upload validation. More pixels do not always improve results after provider-side resizing.

#Make the task verifiable

For a chart, ask for the axis labels and visible values before asking for a trend. For a document, request a source page or region with each field and keep unknown values null. Crop an authorized region if text is unreadable; do not substitute a confident guess.

Validate critical numbers against the source. Remove secrets and unnecessary personal data before upload. Image interpretation is not proof of identity, exact counting or a guarantee of OCR accuracy.

Vision documentation↗

Published by
JR Academy
Learning resources

Individual authors and reviewers are credited where recorded.

System Design

Core system design concepts and practical case studies

Learn the trade-offs and patterns that matter in technical interviews.

Open System Design →

Related Roadmaps

Done reading? Next steps