{"course":{"slug":"building-with-ai","title":"Building with AI","url":"https://addaly.com/learn/building-with-ai","level":"intermediate","track":"build"},"lesson":{"slug":"images-files-and-audio-in","title":"Sending images, PDFs and audio, and what they cost","url":"https://addaly.com/learn/building-with-ai/images-files-and-audio-in","position":10,"of":80,"minutes":9,"answer":"Images cost roughly width times height over 750 in tokens, PDFs need a text-layer-then-render fallback, and every extracted value should carry a verbatim quote you can find in the source.","keyIdea":"Images cost roughly width times height over 750 in tokens, PDFs need a text-layer-then-render fallback, and every extracted value should carry a verbatim quote you can find in the source, because a model asked to read something illegible will invent something plausible instead of refusing."},"body":{"format":"markdown","text":"## An image is tokens too\n\nA vision model does not process a picture as a picture. The image is cut into patches, each patch is embedded, and the resulting vectors are placed in the same sequence as your text tokens. So an image has a token count, it consumes context window, and it appears on your bill.\n\nThe formula most providers use is close to **width × height ÷ 750**. Some practical values:\n\n- 512 × 512: about 350 tokens\n- 1092 × 1092: about 1,590 tokens, which is near the point of diminishing returns for most providers\n- 2000 × 1500: about 4,000 tokens, and often downscaled by the provider anyway\n\nA thousand-token image is roughly 750 words of text. Send eight product photos in one request and you have spent more on images than on your entire prompt.\n\nThe optimisation follows directly: **resize before sending.** If the answer depends on the overall layout of a page, 1024 pixels on the long edge is plenty. If it depends on small print, crop to the region rather than sending the whole page at high resolution: a 400 × 300 crop of the total line on an invoice costs 160 tokens and works better than a 3000-pixel scan, because you have removed the distractors as well as the cost.\n\n## PDFs are the hard case\n\nThere are three ways to get a PDF into a model, and they fail differently.\n\n**Extract the text layer.** `pdfplumber`, `PyMuPDF` and `pdftotext` are free and fast. This works perfectly for PDFs generated by software and not at all for scans, which have no text layer. It also destroys most table structure: a two-column layout often comes out interleaved line by line, producing text that reads like nonsense and that a model will confidently summarise anyway.\n\n**Render pages to images and send them to a vision model.** Preserves layout, handles scans, costs 1,500 to 2,000 tokens per page. A 40-page contract is 60,000 to 80,000 tokens per question, which is real money if you ask more than one.\n\n**Use a document-specific OCR pipeline**: Tesseract is the free classic, `docTR` and Surya are stronger open-source options, and every cloud has a paid one. You get text with coordinates, which lets you rebuild tables and, crucially, **cite a page and a position** later.\n\nThe pattern that survives contact with reality is hybrid: extract the text layer, and if it comes back empty or nearly empty, fall back to rendering pages. Store both the text and the page image reference, so that when a user asks where a number came from you can show them.\n\nBe honest about failure. Handwriting, faded thermal receipts, rotated scans, stamps over text and multi-column forms all break OCR and vision models alike, and the failure is usually **silent**: you get a plausible number that is wrong by a digit. For anything financial, extract with a model and then verify with arithmetic: do the line items sum to the stated total? A model that cannot add will happily report a total that does not match the rows above it, and a three-line check catches it.\n\n## Audio\n\nTwo routes.\n\n**Transcribe first.** Whisper is open-weight and free; `faster-whisper` runs the small model on a CPU at several times real time, so an hour of audio transcribes in a few minutes on a laptop. You then have text, which is cheap, searchable, diffable and easy to evaluate. This is the right default for meetings, interviews, calls and voice notes.\n\n**Send audio to a model that accepts it natively.** You keep tone, hesitation, overlapping speakers and emphasis, all of which a transcript discards. You pay considerably more and you lose the intermediate artefact you could have inspected.\n\nTranscription has known, structured failure modes worth designing around: proper nouns and Indian names are frequently mangled, code-switching between languages mid-sentence confuses language detection, and (the dangerous one) Whisper-family models can **hallucinate fluent text during silence**, producing sentences nobody said. Voice-activity detection before transcription removes most of that.\n\n## Where the model must not be trusted\n\nAcross all three input types, the same rule holds and it is the one that separates a demo from a product. **A model reading a document is doing recognition and inference at the same time, and it will not tell you which is which.** Asked for an invoice date it cannot read, it will supply a well-formatted, plausible date rather than say the scan is illegible.\n\nSo build the exit ramp:\n\n- Ask for a **verbatim quote** alongside every extracted value, then check the quote actually appears in the text you supplied. If it does not, the value is invented.\n- Require an explicit `null` for anything unreadable, and say so in the prompt.\n- Apply arithmetic and format checks: dates in range, totals that add up, tax at a legal rate.\n- Route anything that fails to a human, and count how often that happens. That count is your real accuracy number."},"check":{"question":"An invoice reader extracts dates and totals from scanned PDFs with 96% accuracy in testing, but finance reports occasional wrong figures that nobody caught. What design change addresses the mechanism?","options":[{"text":"Send the pages at higher resolution so the model can read small print.","correct":false,"tempting":"Improves recognition on some pages while doing nothing about the cases where the model fills an unreadable field with a plausible value."},{"text":"Require a verbatim quote for each value, verify the quote appears in the source text, and check that line items sum to the stated total.","correct":true},{"text":"Use a larger model, since accuracy scales with capability.","correct":false,"tempting":"Raises the rate of correct reads without adding any way to detect the incorrect ones, which is the part finance actually needs."},{"text":"Lower the temperature to zero so extraction is deterministic.","correct":false,"tempting":"Makes the same wrong answer reproducible rather than making wrong answers detectable."}]},"prev":{"slug":"a-model-on-your-own-machine","title":"Running a model on a laptop with no GPU","url":"https://addaly.com/learn/building-with-ai/a-model-on-your-own-machine"},"next":{"slug":"the-prompt-is-an-interface","title":"A prompt is an interface, not a paragraph","url":"https://addaly.com/learn/building-with-ai/the-prompt-is-an-interface"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Exam keys checked blind by a second model: 3,665 of 3,666 agreed. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Sending images, PDFs and audio, and what they cost', in Building with AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/building-with-ai/images-files-and-audio-in (Accessed: 13 October 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Sending images, PDFs and audio, and what they cost","courseTitle":"Building with AI","module":{"index":1,"slug":"the-call-underneath-everything","title":"The call underneath everything"},"answer":null,"keyIdea":"Images cost roughly width times height over 750 in tokens, PDFs need a text-layer-then-render fallback, and every extracted value should carry a verbatim quote you can find in the source, because a model asked to read something illegible will invent something plausible instead of refusing.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"an-image-is-tokens-too","runs":[{"text":"An image is tokens too"}]},{"t":"p","runs":[{"text":"A vision model does not process a picture as a picture. The image is cut into patches, each patch is embedded, and the resulting vectors are placed in the same sequence as your text tokens. So an image has a token count, it consumes context window, and it appears on your bill."}]},{"t":"p","runs":[{"text":"The formula most providers use is close to "},{"text":"width × height ÷ 750","b":true},{"text":". Some practical values:"}]},{"t":"ul","items":[[{"text":"512 × 512: about 350 tokens"}],[{"text":"1092 × 1092: about 1,590 tokens, which is near the point of diminishing returns for most providers"}],[{"text":"2000 × 1500: about 4,000 tokens, and often downscaled by the provider anyway"}]]},{"t":"p","runs":[{"text":"A thousand-token image is roughly 750 words of text. Send eight product photos in one request and you have spent more on images than on your entire prompt."}]},{"t":"p","runs":[{"text":"The optimisation follows directly: "},{"text":"resize before sending.","b":true},{"text":" If the answer depends on the overall layout of a page, 1024 pixels on the long edge is plenty. If it depends on small print, crop to the region rather than sending the whole page at high resolution: a 400 × 300 crop of the total line on an invoice costs 160 tokens and works better than a 3000-pixel scan, because you have removed the distractors as well as the cost."}]},{"t":"h2","id":"pdfs-are-the-hard-case","runs":[{"text":"PDFs are the hard case"}]},{"t":"p","runs":[{"text":"There are three ways to get a PDF into a model, and they fail differently."}]},{"t":"p","runs":[{"text":"Extract the text layer.","b":true},{"text":" "},{"text":"pdfplumber","code":true},{"text":", "},{"text":"PyMuPDF","code":true},{"text":" and "},{"text":"pdftotext","code":true},{"text":" are free and fast. This works perfectly for PDFs generated by software and not at all for scans, which have no text layer. It also destroys most table structure: a two-column layout often comes out interleaved line by line, producing text that reads like nonsense and that a model will confidently summarise anyway."}]},{"t":"p","runs":[{"text":"Render pages to images and send them to a vision model.","b":true},{"text":" Preserves layout, handles scans, costs 1,500 to 2,000 tokens per page. A 40-page contract is 60,000 to 80,000 tokens per question, which is real money if you ask more than one."}]},{"t":"p","runs":[{"text":"Use a document-specific OCR pipeline","b":true},{"text":": Tesseract is the free classic, "},{"text":"docTR","code":true},{"text":" and Surya are stronger open-source options, and every cloud has a paid one. You get text with coordinates, which lets you rebuild tables and, crucially, "},{"text":"cite a page and a position","b":true},{"text":" later."}]},{"t":"p","runs":[{"text":"The pattern that survives contact with reality is hybrid: extract the text layer, and if it comes back empty or nearly empty, fall back to rendering pages. Store both the text and the page image reference, so that when a user asks where a number came from you can show them."}]},{"t":"p","runs":[{"text":"Be honest about failure. Handwriting, faded thermal receipts, rotated scans, stamps over text and multi-column forms all break OCR and vision models alike, and the failure is usually "},{"text":"silent","b":true},{"text":": you get a plausible number that is wrong by a digit. For anything financial, extract with a model and then verify with arithmetic: do the line items sum to the stated total? A model that cannot add will happily report a total that does not match the rows above it, and a three-line check catches it."}]},{"t":"h2","id":"audio","runs":[{"text":"Audio"}]},{"t":"p","runs":[{"text":"Two routes."}]},{"t":"p","runs":[{"text":"Transcribe first.","b":true},{"text":" Whisper is open-weight and free; "},{"text":"faster-whisper","code":true},{"text":" runs the small model on a CPU at several times real time, so an hour of audio transcribes in a few minutes on a laptop. You then have text, which is cheap, searchable, diffable and easy to evaluate. This is the right default for meetings, interviews, calls and voice notes."}]},{"t":"p","runs":[{"text":"Send audio to a model that accepts it natively.","b":true},{"text":" You keep tone, hesitation, overlapping speakers and emphasis, all of which a transcript discards. You pay considerably more and you lose the intermediate artefact you could have inspected."}]},{"t":"p","runs":[{"text":"Transcription has known, structured failure modes worth designing around: proper nouns and Indian names are frequently mangled, code-switching between languages mid-sentence confuses language detection, and (the dangerous one) Whisper-family models can "},{"text":"hallucinate fluent text during silence","b":true},{"text":", producing sentences nobody said. Voice-activity detection before transcription removes most of that."}]},{"t":"h2","id":"where-the-model-must-not-be-trusted","runs":[{"text":"Where the model must not be trusted"}]},{"t":"p","runs":[{"text":"Across all three input types, the same rule holds and it is the one that separates a demo from a product. "},{"text":"A model reading a document is doing recognition and inference at the same time, and it will not tell you which is which.","b":true},{"text":" Asked for an invoice date it cannot read, it will supply a well-formatted, plausible date rather than say the scan is illegible."}]},{"t":"p","runs":[{"text":"So build the exit ramp:"}]},{"t":"ul","items":[[{"text":"Ask for a "},{"text":"verbatim quote","b":true},{"text":" alongside every extracted value, then check the quote actually appears in the text you supplied. If it does not, the value is invented."}],[{"text":"Require an explicit "},{"text":"null","code":true},{"text":" for anything unreadable, and say so in the prompt."}],[{"text":"Apply arithmetic and format checks: dates in range, totals that add up, tax at a legal rate."}],[{"text":"Route anything that fails to a human, and count how often that happens. That count is your real accuracy number."}]]}],"check":{"question":[{"text":"An invoice reader extracts dates and totals from scanned PDFs with 96% accuracy in testing, but finance reports occasional wrong figures that nobody caught. What design change addresses the mechanism?"}],"options":[{"text":[{"text":"Send the pages at higher resolution so the model can read small print."}],"correct":false,"tempting":[{"text":"Improves recognition on some pages while doing nothing about the cases where the model fills an unreadable field with a plausible value."}]},{"text":[{"text":"Require a verbatim quote for each value, verify the quote appears in the source text, and check that line items sum to the stated total."}],"correct":true,"tempting":null},{"text":[{"text":"Use a larger model, since accuracy scales with capability."}],"correct":false,"tempting":[{"text":"Raises the rate of correct reads without adding any way to detect the incorrect ones, which is the part finance actually needs."}]},{"text":[{"text":"Lower the temperature to zero so extraction is deterministic."}],"correct":false,"tempting":[{"text":"Makes the same wrong answer reproducible rather than making wrong answers detectable."}]}],"order":[3,1,0,2],"why":null},"prev":{"slug":"a-model-on-your-own-machine","title":"Running a model on a laptop with no GPU","minutes":10},"next":{"slug":"the-prompt-is-an-interface","title":"A prompt is an interface, not a paragraph","minutes":9}}}