Sub topic 1
How Multimodal Models Read Images and Documents
Prerequisites
This chapter assumes you have:
- Basic Python, including reading files and working with bytes.
- Experience calling an LLM chat API over HTTP or through an SDK.
- An understanding of JSON request bodies.
- A working idea of what tokens and context windows are.
What "multimodal" means in practice
A modality is a type of input, such as text, images, or audio. A multimodal model accepts more than one type in the same request. In this tutorial the extra types are images and PDF documents.
From your code, a visual input is not a separate call. You put the image or PDF into the same message that carries your text question. The model then answers using both.
How the model turns pixels into something it can read
A language model works on tokens, not files. Before an image reaches the model, the provider converts it into a sequence of image tokens. The usual steps are:
- The image is resized if it is larger than the provider allows.
- It is cut into small patches.
- A vision encoder, which is a neural network trained on images, turns each patch into a vector of numbers.
- These vectors are placed in the model's context next to the text tokens.
From that point on, the model attends to image tokens and text tokens together. It does not run a separate OCR (optical character recognition) program. Reading text in an image is something the model learned to do, so it can be wrong in ways a dedicated OCR engine usually is not. Later chapters cover those failure modes.
Image tokens count against the context window and appear on your bill. A larger image generally produces more tokens, up to a provider limit.
How PDFs differ from images
A PDF is a container. A page can hold real text, embedded images, vector drawings, or a scan that is only a picture of text.
When a provider supports PDF input, it typically does two things for each page:
- It extracts the text layer, if one exists.
- It renders the page as an image.
The model receives both. That lets it use exact text where the file has it and use the visual layout for charts, tables, and scans. Providers differ in page limits and in what they extract, so check the documentation for the one you use.
The request shape
Every provider follows the same idea: a message holds a list of typed content blocks. Each block is one piece of content, such as a text block or an image block.
Output is still text. The models covered here read images and documents but reply with text.
Key consequences
| Fact | What it means for you |
|---|---|
| Images become tokens | Cost, latency, and context use grow with image size and count. |
| The model reads, it does not run OCR | Small or blurry text can be misread without any error. |
| A PDF yields text and page images | Native PDF input can cost more than text alone. |
| Everything shares one context | Many large images can crowd out your prompt and history. |
Check your understanding
Exercise
A scanned PDF has no text layer. Which part of native PDF input will the model rely on, and why does that matter for accuracy?
Show answer
It relies on the rendered page images, because there is no text to extract. The model must read the text visually, so small, faint, or skewed print can be misread. Accuracy then depends on image quality, as with a plain image input.
Exercise
Why can sending ten large images in one request cause problems even if each image is under the size limit?
Show answer
Each image becomes many tokens in the same context window. Together they raise cost and latency and can leave little room for your prompt, earlier messages, and the answer.