Skip to main content

Vision, PDF & File Input

Intermediate
What you'll learn
  • Why Claude is multimodal: images and documents in one message
  • The three ways to send a file: Base64, URL, and the Files API
  • When to reuse an upload by file_id to save cost and time
  • What vision is great for — extraction, visual understanding, document Q&A
  • How to use it safely: resolution limits and verifying critical numbers

Claude is multimodal: you can include images and documents (like PDFs) in a message and ask questions about them — extract data, describe a chart, summarize a contract, read a screenshot.

Three ways to send a file

Guided walkthrough1 of 3
  1. Encode the bytes inline in the request. Simplest for one-offs.

Here is what an image content block looks like alongside a text question:

# Conceptual: an image content block alongside text (see docs for exact fields)
messages=[{
"role": "user",
"content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": b64}},
{"type": "text", "text": "What does this chart show? Give the top 3 takeaways."},
],
}]

PDFs work similarly (a document content block); Claude can read text and visual layout, and you can request citations back to where in the document an answer came from.

What it's great for

Pro tip
  • Extraction — pull structured data from invoices, forms, tables (pair with Structured Output: /docs/api/structured-output).
  • Understanding visuals — charts, diagrams, screenshots, UI.
  • Document Q&A — ask questions across a long PDF with citations.

A quick copy-paste starter for document Q&A:

Document Q&A prompt

What does this chart show? Give the top 3 takeaways.

Tips

Key takeaways
  • Reuse with file_id when sending the same big document repeatedly — cheaper and faster.
  • Resolution/size matter — very large images may be downscaled; check limits.
  • Verify extracted numbers — vision is strong but not infallible; spot-check critical figures.
Watch out
  • Vision is strong but not infallible — always spot-check critical figures. See Hallucinations: /docs/foundations/hallucinations.

Check yourself

0/3
  1. Which method lets you upload a file once and reference it across many requests by file_id?
  2. What can you request back from Claude when doing document Q&A on a PDF?
  3. Why should you spot-check critical extracted numbers?

Next