Vision and Document Understanding

Send images, screenshots and PDFs to models for description, extraction, charts and visual question answering.

Intermediate · about 4 hours · difficulty 3/5

Learn first: Structured Outputs and JSON Schema

Most frontier models accept images and PDFs as input alongside text. This unlocks invoice extraction, screenshot debugging, chart reading, form processing and visual search.

How it works in the API

You attach an image as base64 data or a URL in a content block next to your text prompt. PDFs can often be sent directly; the provider renders pages and may also extract text. Images are converted into tokens, so resolution affects cost and latency. Resize large images to what the task actually needs.

Good practices

  • Put the image before the question and say exactly what to extract.
  • Combine vision with structured outputs for extraction: a schema for invoice number, date, totals and line items.
  • For multi-page documents, process page by page or chunk, then merge.
  • Validate extracted numbers with code (do line items sum to the total?).

Limitations

Models can misread small text, count objects poorly, confuse spatial relationships and hallucinate details in blurry images. For high-accuracy OCR at scale, a dedicated OCR or document parsing service may still be cheaper and more reliable, with the model handling interpretation.

Multimodal embeddings

Models such as CLIP-style embeddings place images and text in one vector space, enabling "search photos by description" and multimodal RAG.

Good enough to move on

You can extract structured data from a batch of receipts or invoices with a vision model, validate it with code, and report accuracy against hand-labelled ground truth.

Key concepts

  • Image and PDF content blocks
  • Resolution, tokens and cost
  • Structured extraction from images
  • Multi-page document processing
  • Vision limitations
  • Multimodal embeddings

Mini project

Build a receipt scanner: upload photos, extract merchant, date, total and line items into a Pydantic or Zod schema, check that the line items sum to the total, and flag mismatches for review.

Check yourself

Why should you verify a vision model's extracted invoice total with code instead of trusting it?

Free resources