Sub topic 1
How Multimodal Models Read Images and Documents
Prerequisites
Assume you know basic Python, JSON request bodies, and how to call an LLM API. You should also understand that tokens measure model input and output, and that context windows limit how much data a request can contain.
How multimodal models read images and documents
A multimodal model accepts more than text. A message contains typed content blocks, such as a text block, image block, or document block. The model processes these blocks together, so a question can refer to visual content in the same message.
The model does not receive an image as human-readable pixels in your prompt. The API transports the file using a supported source format. The model then analyzes visual features, text, layout, and relationships between objects. Results depend on image quality and the model's visual capabilities.
import json
message = {
"role": "user",
"content": [
{"type": "text", "text": "What trend does this chart show?"},
{
"type": "image",
"source": {
"type": "url",
"url": "https://example.com/chart.png",
},
},
],
}
print(json.dumps(message, indent=2))Mixing text and images in one message
Place the instruction and visual input in the same user message when the instruction refers to that input. With several images, label them in the text, such as “Compare image 1 with image 2.” Provider schemas differ, so use the exact block names required by your SDK or API.
Supported formats and size limits
Common image formats include PNG, JPEG, GIF, and WebP. PDF support varies. Providers also impose limits on file size, pixel dimensions, page count, or total request size. Check current provider documentation rather than assuming that a format or limit is universal.
| Input | Typical use | Main concern |
|---|---|---|
| PNG or JPEG | Charts, photos, screenshots | Resolution and file size |
| Reports and forms | Page limits and provider support |
Choosing how to supply the data
Use base64 when your application already has local bytes and the provider accepts inline data. Use a URL when the provider can securely fetch a stable, accessible object. Use an uploaded file when you will reuse a large document or need provider-managed processing.
| Method | Advantage | Trade-off |
|---|---|---|
| Base64 | Self-contained request | Increases request size |
| URL | Small request body | Requires suitable access |
| File upload | Reusable input | Adds upload and lifecycle handling |
Exercise
Which source is usually simplest for a local image used once?
Show answer
Base64 inline data, provided the provider supports it and the encoded request stays within its size limits.