How to let AI read a PDF — three ways and what each costs

The first thing to know before throwing a PDF at a model: it doesn't read the file. It looks at it.
Every page becomes an image, and only then does the model work out what's drawn there. That explains the oddities: why a scan works as well as a real document, why tables sometimes drift, and why a hundred-page report costs noticeably more than a hundred pages of text.
Here are three ways to feed it a PDF — from "30 seconds" to "a thousand documents."
The numbers first, so nothing surprises you
Current flagship limits (August 2026, from the official docs):
- Gemini API: up to 1000 pages and 50 MB per document. Each page counts as 258 tokens. A file uploaded via the Files API is stored for 48 hours, storage itself is free.
- Claude API: up to 32 MB per request and up to 600 pages (or 100 when the model's window is under a million tokens). One page runs about 1500–3000 text tokens plus image tokens, because the page is photographed too.
The gap in counting isn't a typo — providers price documents differently. The practical takeaway is the same: a 100-page PDF isn't "a hundred pages," it's tens of thousands of tokens in every request. Ask five questions in a row and the document ships five times, whole.
Way 1. Drop it in the chat (30 seconds)
For a one-off — "pull the terms out of this contract," "summarise this handbook" — don't write code. Open a chat and drag the file in.
One thing to do immediately: ask for citations. Instead of "tell me what's in here," say "list the payment clauses with the page number next to each." The page number is your check: if the model invented a clause, the number won't match.
The one downside: nothing is automated. One file, two hands.
Way 2. Send it through the API (for your own app)
Now we're writing code. The logic is the same across providers: upload the file first, then reference it in the request.
Step 1. Upload the file. For Gemini that's the Files API:
curl -s "https://generativelanguage.googleapis.com/upload/v1beta/files?key=$GEMINI_API_KEY" \
-H "X-Goog-Upload-Protocol: multipart" \
-F "metadata={'file':{'display_name':'report'}};type=application/json" \
-F "[email protected];type=application/pdf"
The response is JSON with a uri field — the file's address on the server. That's what you need next.
Step 2. Ask a question referencing the file. Text in one part, the document in another:
curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash:generateContent?key=$GEMINI_API_KEY" \
-H 'Content-Type: application/json' -d '{
"contents": [{"parts": [
{"file_data": {"mime_type": "application/pdf", "file_uri": "PASTE_URI_FROM_STEP_1"}},
{"text": "List every amount and deadline. Give the page for each."}
]}]
}'
Step 3. Ask for structure, not prose. If the answer feeds back into code, put the format in the prompt: "return a JSON array of objects with page, amount, deadline." How to make that format stick is covered in structured output.
Step 4. Don't re-upload per question. The reference from step 1 is reusable for 48 hours. That saves bandwidth, not tokens: the contents still travel to the model on every call.
Way 3. When the document is huge — or there are hundreds
If the PDF blows the limit, there are many documents, or users are asking the questions, you can't drag the whole file into every request. Different scheme:
- Extract the text with a library (
pypdf,pdfplumber). Fast and free — no model needed here at all. - Check that text actually came out. Empty output means it's a scan, an image with no text layer. Then it's OCR, or back to way 2, where the page is recognised as an image anyway.
- Cut it into chunks of 300–800 words, ideally on meaningful boundaries — sections, not a character counter.
- Put them in a vector database and pull 3–5 relevant chunks per question. That's RAG: the model gets a couple of paragraphs, not the whole report.
Yes, it's far more work than two curls. But a question against a thousand PDFs costs the same as a question against one — whereas with way 2 the context window runs out on document three.
What you get
After way 2 you have a working slice of an app: a user drops in an invoice or a contract, the service returns JSON with amounts and dates, and you fill your form from it. That's exactly the feature that took a team half a year five years ago — back then you trained a recogniser per form type. Now it's two requests and a prompt asking for page numbers.
Will a model read a scan or a photo of a document?
Yes, via way 1 or way 2 — the page is processed as an image regardless, which is multimodality at work. Library text extraction on a scan, though, returns nothing: there's no text layer to extract.
Why do tables sometimes come out scrambled?
Because a table in a PDF isn't a table — it's lines and text blocks with coordinates. The model rebuilds the structure from appearance and can slip on merged cells. Fix it by asking for one JSON object per row and spot-checking a couple of rows.
How do I cut the bill on large PDFs?
Three moves that work: send only the pages you need instead of the whole file; ask all your questions in one request instead of five; use a smaller model for plain extraction. The rest is in the guide on reducing AI costs.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





