A customer walks up to the Bookshop till and holds out a phone: "Do you have this one?" The screen shows a photo of a book cover. The cashier looks at the photo, recognises the book, then checks the stock on the computer. The Bookshop assistant can do the same with a multi-modal model: a model that can process or produce more than one kind of data. That means text, images and audio, even documents such as PDFs. In this story, the vision model (a model that can read images) is the cashier's eyes: the model only recognises the book. Stock and prices still come from the database: the cashier's computer.
What goes in and what comes out isn't always the same kind of data:
gpt-6-lunaand every Claude model take images in, but answer in text.gpt-transcribeturns speech into text (speech-to-text).gpt-4o-mini-ttsturns text into speech (text-to-speech).
Images in: requests to OpenAI and Claude
The flow is the same as for a text question. The browser sends the photo to your server (POST /api/assistant/photo). Then the server calls the provider, because the API key lives only on the server. The photo travels as base64: the file's bytes written as text, about 4/3 of the original size. The request shape differs per provider (checked in each one's documentation, 11 October 2026). The code below sends the same question to OpenAI, then to Claude. b64 holds the photo as base64:
// OpenAI, Responses API: input_image with a full data URL
const r = await openai.responses.create({
model: "gpt-6-luna",
input: [{ role: "user", content: [
{ type: "input_text", text: "What is the title on this cover? Answer with the title only." },
{ type: "input_image", image_url: `data:image/jpeg;base64,${b64}`, detail: "auto" },
] }],
});
// Claude, Messages API: an image block, base64 WITHOUT the "data:" prefix
const m = await anthropic.messages.create({
model: "claude-haiku-5-5",
max_tokens: 100,
messages: [{ role: "user", content: [
{ type: "image", source: { type: "base64", media_type: "image/jpeg", data: b64 } },
{ type: "text", text: "What is the title on this cover? Answer with the title only." },
] }],
});
- OpenAI:
image_urlholds an image URL, or a data URLdata:image/jpeg;base64,...(text that holds the file itself, starting withdata:). Afile_idworks too, the id of a file uploaded earlier through the Files API. Accepted formats: PNG, JPEG, WEBP and non-animated GIF.detail(how finely the image is processed) islow,high,originalorauto(the default). - Claude:
source.typecan bebase64,urlorfile.dataholds only the base64, and the file type goes inmedia_type. Accepted formats: JPEG, PNG, GIF, WebP, at most 10 MB per image (as base64). The docs suggest putting the image before the text. - The model only returns the title. The server matches that title against the books table, then stock and price are read with an SQL query: "The Rainbow Troops, 12 in stock, $18". The vision model can misread (small text, a tilted photo), so when the title matches no book, ask the customer which book it is.
Images become tokens: count first
Images are billed as input tokens. How to count them is written in the documentation:
- OpenAI (the "Images and vision" guide): the image is covered with 32 × 32 pixel squares, called patches. Tokens = patches × a multiplier, rounded up. For
gpt-6-astraand thegpt-5.6family,highdetail has a budget of 2,500 patches (a bigger image is shrunk first) and a 1.2 multiplier.gpt-6-lunaaccepts images, but isn't in that guide's table yet. So the OpenAI numbers in the table below are an estimate with the same rule. Check the real number inusage.input_tokens. - Claude (the "Vision" page): 28 × 28 pixel patches, and tokens = ⌈width / 28⌉ × ⌈height / 28⌉. The ⌈ ⌉ signs mean rounded up. Claude 4.7 and later models (including
claude-haiku-5-5) only shrink an image when its long side passes 2,576 pixels or its tokens pass 4,784.
Before you look at the table, guess. A customer's phone photo of a cover is 1200 × 1600 pixels, and the Bookshop assistant's whole text prompt is about 1,200 tokens. On Claude, how many tokens is the photo: about 300, about 2,500, or about 25,000?
| Photo size | OpenAI (patches × 1.2) | Claude |
|---|---|---|
| 1200 × 1600 (straight from the phone) | 38 × 50 = 1,900 patches → 2,280 tokens | 43 × 58 = 2,494 tokens |
| 768 × 1024 | 24 × 32 = 768 patches → 922 tokens | 28 × 37 = 1,036 tokens |
| 576 × 768 | 18 × 24 = 432 patches → 519 tokens | 21 × 28 = 588 tokens |
The original photo on Claude is 2,494 tokens, twice the whole text prompt. claude-haiku-5-5 and gpt-6-luna have the same input price, $0.10 per 1 million tokens, so 1,000 original photos on Claude cost $0.25, and only $0.06 once shrunk to 576 × 768. On gpt-6-astra ($10 per 1 million tokens), using the token counts in the OpenAI column, 1,000 original photos cost $22.80, and shrunk ones $5.19. To read the title on a cover, a long side of 768 pixels is plenty.
Shrink in the browser before uploading
In the shrinkPhoto function below, longSide is the longest side you want (768 by default):
async function shrinkPhoto(file, longSide = 768) {
const bitmap = await createImageBitmap(file); // the EXIF orientation is already applied
const scale = Math.min(1, longSide / Math.max(bitmap.width, bitmap.height));
const canvas = document.createElement("canvas");
canvas.width = Math.round(bitmap.width * scale); // 1200 -> 576
canvas.height = Math.round(bitmap.height * scale); // 1600 -> 768
canvas.getContext("2d").drawImage(bitmap, 0, 0, canvas.width, canvas.height);
return new Promise((done) => canvas.toBlob(done, "image/jpeg", 0.85));
}
createImageBitmapreads the photo file and already turns it the right way up, as EXIF says (see the next section). A canvas (a drawing area in the browser) then draws the photo again at the new size.scale=longSide÷ the photo's longest side.Math.min(1, ...)keeps small photos from being enlarged.toBlobmakes a new JPEG file from the canvas pixels. The result: the upload is lighter, there are fewer tokens, and the server never has to take a 4 MB photo.
Photos carry a location: strip EXIF
EXIF is a metadata block (data about the photo) inside a JPEG file. A JPEG file is made of several segments, and each segment starts with a two-byte marker. EXIF sits in the APP1 segment, with the byte marker FF E1. It holds the camera make, the time, and often the GPS coordinates where the photo was taken. So a cover photographed at home carries the location of the customer's home. The Lab builds a real JPEG byte by byte: 362 bytes, with a 182-byte EXIF block. That block holds GPS 6°12'37.2" S, 106°50'56.4" E (-6.210333, 106.849) and the time 2026:10:11 08:12:07.
The removeExif function below reads the file one segment at a time and copies every segment except APP1:
function removeExif(bytes) {
const parts = [bytes.subarray(0, 2)]; // SOI: the start of a JPEG file
let i = 2;
while (i < bytes.length) {
const marker = bytes[i + 1];
if (marker === 0xda) { parts.push(bytes.subarray(i)); break; } // SOS: image data to the end
const length = (bytes[i + 2] << 8) | bytes[i + 3];
if (marker !== 0xe1) parts.push(bytes.subarray(i, i + 2 + length)); // APP1 (EXIF) is skipped
i += 2 + length;
}
const result = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
let at = 0;
for (const p of parts) { result.set(p, at); at += p.length; }
return result;
}
- Each round of the loop reads one segment:
markeris the segment's second byte (0xe1fromFF E1), andlengthis in the two bytes after that. A0xe1segment (APP1) is skipped. From the0xdasegment (SOS), the rest of the file is copied whole, because it is image data. - All the
partsare copied into oneUint8Arraywith.set(). Another way,result.push(...bytes.slice(i))into a plain array, works only on small files: a real phone photo (hundreds of KB) makes it fail withRangeError: Maximum call stack size exceeded.
In the Lab, the 362-byte JPEG becomes 180 bytes after removeExif: the GPS is gone, and the browser still shows it. The model doesn't read metadata (OpenAI's and Claude's docs both say so). But the file passes through your server, sits in storage, and can be shown again with its GPS, in a review for instance. A new JPEG from toBlob is made only from the canvas pixels, so the original file's EXIF isn't copied. Still, not every upload goes through a canvas, so the server strips it too, for example by saving the image again as a new JPEG file.
Speech: from and to text
- Speech-to-text on the server:
POST /v1/audio/transcriptionswithgpt-transcribe, the model OpenAI recommends as of October 2026. Files can be up to 25 MB (flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm). You give a language hint withlanguages: ["en"], and the price is $0.0045 per minute of audio.whisper-1($0.006 per minute) is still the only model that gives timestamps (times) for each word. But it is deprecated and shuts down on 26 February 2027. Translation into English (/v1/audio/translations) shuts down on the same date and moves to/v1/realtime/translations. - Text-to-speech on the server:
POST /v1/audio/speechwithgpt-4o-mini-tts, avoice(such ascoral), andinstructionsfor the tone. The result is an MP3 file. This model is deprecated and shuts down on 6 January 2027 (checked November 2026). Its replacement,gpt-realtime-2.1-mini, works only through the Realtime API (OpenAI's API for live speech), not through/v1/audio/speech. OpenAI's policies require you to tell listeners the voice is AI-generated. - In the browser, free: the Web Speech API, the browser's built-in speech tools.
speechSynthesisreads text aloud, in Chrome, Edge, Firefox and Safari. The voices come from the operating system, so which voices you get depends on the device.SpeechRecognition(listening) is in Chrome and Edge (without thewebkitprefix since Chrome 139), and in Safari aswebkitSpeechRecognition. Desktop Firefox has had it since version 160, Firefox for Android doesn't yet (MDN compatibility data, November 2026). In Chrome, the user's recorded speech may go to a recognition server unlessprocessLocally = true.
The code below shows a record button in a browser that has no SpeechRecognition (under either name), then reads the stock aloud:
const Recognition = globalThis.SpeechRecognition ?? globalThis.webkitSpeechRecognition;
if (!Recognition) showRecordButton(); // record with MediaRecorder, send to /api/transcribe
speechSynthesis.speak(Object.assign(new SpeechSynthesisUtterance("The Rainbow Troops: 12 in stock."), { lang: "en-US" }));
PDF documents
A supplier sends a 12-page price list as a PDF:
- OpenAI takes it as
{ type: "input_file", filename: "prices.pdf", file_data: "data:application/pdf;base64,..." }(orfile_id,file_url). The API extracts the text and an image of every page, and each file must be under 50 MB. - Claude uses
{ type: "document", source: { type: "base64", media_type: "application/pdf", data } }. Its limits are 128 MB per request and 600 pages (100 when the context window is under 1 million tokens). Each page counts as about 1,500 to 3,000 text tokens, plus its image tokens.
Ask for the PDF's content as JSON with Structured Outputs (the AI-Powered Forms & Content lesson). Then the Bookshop's admin checks it before the catalogue is updated.
Alt text: a draft from the model, a decision by a person
A vision model can draft alt text from a product photo: "An orange book cover with a dark title band". The model can misread the title, doesn't know the page's context, and doesn't know which images are only decoration (decoration gets alt=""). The admin reads the draft, corrects it to "Cover of the novel The Rainbow Troops by Andrea Hirata", and only then saves it. The same goes for speech transcripts (the text that speech-to-text produces): show them as text that can still be corrected.
⚠️ Raw photos, mixed-up base64 and GPS sent with the photo
- Sending the raw photo. 1200 × 1600 = 2,494 tokens on Claude. Shrunk to 576 × 768, it's 588. Shrink in the browser, and cap the upload size on the server.
- Mixing up the base64 formats. OpenAI needs the full data URL (
data:image/jpeg;base64,...) inimage_url, while Claude needs only the base64 indataplusmedia_type. - Forgetting EXIF. The GPS of the customer's home gets stored. Strip it on the client and on the server.
- Counting on SpeechRecognition in every browser. Not every browser has it, for example Firefox for Android. Always offer text input, or record and upload.
- Trusting the model's eyes for stock, or publishing alt text nobody read. The model only reads the title. Stock comes from SQL, and a person checks the alt text.
TL;DR: A multi-modal model processes or produces more than one kind of data: text, images, audio, PDFs. Photos go through your server as base64. At OpenAI, the shape is input_image with a data URL (data:image/jpeg;base64,...) in image_url (detail level: low, high, original, auto). At Claude, it's an image block with a base64 source without the data: prefix, plus media_type (the file type). Images are counted in patches (squares of pixels). OpenAI: the number of 32 px patches times 1.2 (an estimate for gpt-6-luna, check usage). Claude: ⌈width/28⌉ × ⌈height/28⌉ (rounded up). A 1200 × 1600 photo is 2,280 tokens on OpenAI and 2,494 on Claude. Shrunk to 576 × 768, it's 519 and 588. Shrink in the browser with a canvas (a drawing area) before uploading. Strip EXIF (the photo's metadata in the APP1 segment, often with GPS) on the client and the server. Speech: gpt-transcribe turns speech into text ($0.0045 per minute, language hint languages: ["en"]), gpt-4o-mini-tts turns text into speech (shuts down 6 January 2027; tell listeners the voice is AI). The browser's Web Speech API is free: speechSynthesis (reading aloud) is everywhere, SpeechRecognition (listening) isn't in every browser yet. PDFs: input_file at OpenAI or a document block at Claude, text plus an image of every page. The model reads, the server decides: stock from SQL, and a person checks alt text and extracted data.
⚡ Multi-modal: more than one kind of data
Meaning: A multi-modal model can process or produce more than one kind of data: text, images, audio, even PDFs. Picture a cashier who looks at a cover photo on a customer's phone, then checks the stock on the computer. The vision model (a model that reads images) is the cashier's eyes: it only reads the title on the cover. Stock and price still come from the database: the cashier's computer.
⚡ Images count as tokens too
Write:
const scale = Math.min(1, longSide / Math.max(bitmap.width, bitmap.height));
Guess first: Claude counts images in patches (squares) of 28 × 28 pixels. Tokens = ⌈width / 28⌉ × ⌈height / 28⌉, each side rounded up. A 1200 × 1600 phone photo is 43 × 58 = 2,494 tokens. Shrunk until its long side is 768, how many tokens is it?
588 tokens. The photo becomes 576 × 768, or 21 × 28 patches.
Meaning: bitmap is the photo the browser has read, and longSide the longest side you want (768). scale (what the photo's size is multiplied by) is at most 1, so small photos aren't enlarged. The original photo costs twice the Bookshop assistant's whole text prompt (about 1,200 tokens), and 768 pixels is plenty to read a title.
⚡ Photos carry a location
Meaning: EXIF is a metadata block (data about the photo) in the APP1 segment (part) of a JPEG file. It often includes the GPS coordinates where the photo was taken, such as the customer's home. The removeExif function drops the APP1 segment: the Lab's file goes down from 362 to 180 bytes, the GPS is gone, and the browser still shows it.