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.
pythonimport 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.