Back

Why PDF file limits through model routers are not one number

An actionable investigation into OpenRouter PDF inputs, Gemini Files API, provider routing, and how to design a sane upload UX.

I started with what sounded like a simple product question:

What is the maximum PDF size I can send through OpenRouter?

That question is wrong in a useful way.

After testing OpenRouter routes, Gemini providers, Gemini Files API, Anthropic, OpenAI, the Vercel AI SDK, and several families of generated PDFs, the answer is not a single number like “10 MB” or “50 MB.” A PDF request is a pipeline. The first failing layer determines whether a document works.

transport/fetch → file admission → PDF parser → page-count gate → rendering/tokenization → model context → generation

A 100 MiB PDF can pass if most of those bytes are ignored after %%EOF. A 1 MiB PDF can fail if it has too many pages. A 50 MiB PDF can upload to Gemini Files API and still fail when you try to use it for generation.

If you are building a product where users upload PDFs, this matters. The honest UX is not “max PDF: 50 MB.” The honest UX is a preflight step that says one of:

This post explains the experiment and distills it into concrete builder guidance.

Conclusions first

If you only remember five things, remember these:

  1. Do not show users “max PDF: 50 MB.” That number may only describe upload/admission, not successful model use.
  2. For Gemini native PDF through OpenRouter/Google Vertex, start conservative: direct-read PDFs under roughly 10 MiB / 450 dense pages; split or index beyond that.
  3. Enforce page count separately from bytes. A sparse 1.07 MiB / 1,500-page PDF failed because the route enforced a 1,000-page limit.
  4. Use native PDF for small, layout-sensitive documents; use extraction/indexing for long Q&A. Do not stuff long PDFs into one model call by default.
  5. Make the upload UX return a plan, not a limit: “read directly,” “split,” “OCR,” “index,” or “too large for this route.”

Here is the user-facing policy I would start with for Gemini native PDFs via OpenRouter/Google Vertex:

PDF profileWhat to tell the user
≤10 MiB and ≤450 normal text pages“This PDF is likely to work.”
10–15 MiB or 450–650 dense pages“This PDF is near the reliability boundary. We need to check it before continuing.”
>15 MiB dense text“This PDF is unlikely to work as one native PDF request.”
>1,000 pages“This PDF has too many pages for this route.”
~50 MiB uploaded through Gemini Files API“Upload may succeed, but model use can still fail.”
scanned/image-heavy“File size alone is not enough to predict this. We need to inspect the pages.”

The short version

Here is the most useful summary from the current results.

Route / pathWhat workedWhat failedPractical lesson
OpenRouter → Gemini 3.1 Pro → Google Vertex → native PDF100 MiB padded transport-control PDFsRealistic dense PDFs around 15 MiB / 675 pagesbyte transport is not the same as PDF ingestion
OpenRouter → Gemini 3.1 Pro → Google Vertex → native PDFsparse 1,000-page PDFsparse 1,500-page PDFpage count is a separate hard gate
Gemini Files API directuploaded and activated a ~50 MiB PDFgeneration with that file failedFiles API admission is not generation success
OpenRouter with a Gemini Files API URIn/aPERMISSION_DENIEDFiles API URIs are scoped to the uploading Google project/auth
OpenRouter → Claude Sonnet 4.5 → Anthropicpadded 30 MiB PDFpadded 32 MiB PDFAnthropic exposed a clearer file-size admission limit
Vercel AI SDK → OpenRouter → Google Vertexpadded PDFs through 50 MiBsame caveats as OpenRouter routeSDK layer was not the limiting factor in this probe

The most important product takeaway:

Do not build a PDF upload UX around one advertised MB limit. Build it around a route-specific preflight plan.

Figure 1: where the same PDF request can fail

A PDF request is a pipeline, not one upload limitTransportURL fetch / request bytesAdmissionprovider accepts fileParserPDF graph is readablePage gatepage count allowedRender/tokenpages become inputContextfits model windowGenerationanswer returnsExample failures:• cannot fetch URL• file too large• “no pages”• >1,000 pages• render/token blowup• context exceeded• timeout / lengthA file “working” means it survived every box. A file-size limit only describes one or two boxes.

The UX problem is that users think they uploaded “a PDF,” but your system has to move that PDF through every stage in the diagram.

Figure 2: observed outcomes are not ordered by file size

Same route, different PDF shapes, different outcomesOpenRouter → Gemini 3.1 Pro → Google Vertex → native PDF, plus Gemini Files API admission checkfile sizepages010 MiB15 MiB50+ MiB01,0002,250observed 1,000-page gate10 MiB / 450 pages: pass13 MiB / 600 pages: pass15 MiB / 675 pages: fail50 MiB / 2,250 pages: fail0.71 MiB / 1,000 pages: pass1.07 MiB / 1,500 pages: fail100 MiB padded / 1 real page: passGemini Files API: 50 MiB upload became ACTIVE,but generation with that file failed.

This is why the answer cannot be “the limit is N MiB.” The outcome depends on file size, page count, PDF structure, provider route, and whether you mean upload or generation.

Method

I tested PDFs through OpenRouter’s /api/v1/chat/completions endpoint using public Cloudflare R2 URLs. For provider-specific routing I used provider slugs and disabled fallbacks:

{
  "model": "google/gemini-3.1-pro-preview",
  "provider": {
    "only": ["google-vertex"],
    "allow_fallbacks": false
  },
  "plugins": [
    { "id": "file-parser", "pdf": { "engine": "native" } }
  ]
}

Every test PDF contained a visible marker:

OPENROUTER_PDF_OK

The model was asked to read the PDF and return exactly that phrase. A pass only means the route accepted the request, fetched or received the file, processed enough of the PDF to see the marker, and generated the expected response. It is not a document-understanding benchmark.

The experiment code lives here:

experiments/openrouter-file-limits/

The most important scripts are:

scripts/generate-pdfs.ts                 # padded transport-control PDFs
scripts/generate-pdflib-pdfs.ts          # standards-compliant dense-text PDFs
scripts/generate-pdf-corpus.ts           # sparse-page corpus
scripts/run-openrouter-tests.ts          # direct OpenRouter runner
scripts/run-vercel-ai-sdk-tests.ts       # Vercel AI SDK → OpenRouter runner
scripts/run-gemini-files-api-tests.ts    # Gemini Files API runner

The pipeline model

A provider’s “PDF limit” usually conflates several different limits.

LayerQuestionExample failure
Transport / fetchCan the router/provider fetch or receive the bytes?URL download failure, request too large
File admissionDoes upstream accept or store the file object?file too large, Files API rejection
PDF parserCan upstream parse the PDF graph?The document has no pages
Page-count gateDoes the file exceed a page cap?exceeds the supported page limit of 1000
Rendering / tokenizationCan pages, text, and images become model input?OCR/rendering failure, image-token explosion
ContextDoes the resulting input fit in the model context?input token count exceeds maximum
GenerationCan the model answer cleanly?empty answer, length stop, timeout

This table is the core of the investigation. When someone asks “what PDF size works?”, the real question is: which layer fails first for this PDF, on this provider route, for this task?

Finding 1: transport controls are useful but misleading

The first PDFs were intentionally weird: a tiny valid one-page PDF followed by padding after %%EOF. This isolates transport and URL fetching. The PDF parser can ignore most of the bytes.

Through OpenRouter → Google Vertex → Gemini 3.1 Pro → native PDF, padded PDFs passed up to 100 MiB.

PDF familySizeResult
post-EOF padded50 MiBpass
post-EOF padded75 MiBpass
post-EOF padded100 MiBpass

This does not mean Gemini can read arbitrary 100 MiB PDFs through OpenRouter. It means this route could fetch a 100 MiB object and parse the small valid PDF body at the front.

That distinction turned out to be everything.

Finding 2: realistic PDF structure fails much earlier

I then generated standards-compliant PDFs using pdf-lib: normal pages, fonts, metadata, and lots of text. These are still synthetic, but they are boring valid PDFs rather than hand-written PDF objects.

Google Vertex + Gemini 3.1 Pro + OpenRouter native PDF produced this pattern:

SizePagesResult
1 MiB50pass
10 MiB450pass
11 MiB500pass
12 MiB550inconclusive: provider timeout 524
13 MiB600pass
14 MiB650inconclusive: provider timeout 524
15 MiB675fail: The document has no pages.
20 MiB900fail: The document has no pages.
25 MiB1,125fail: The document has no pages.
30 MiB1,350fail: The document has no pages.
50 MiB2,250fail: The document has no pages.

Two points matter:

  1. The same route that accepted a 100 MiB padded object failed on a normal 15 MiB dense-text PDF.
  2. Near the boundary, some failures were provider timeouts rather than clean validation errors.

The error message is also misleading. These PDFs do have pages. Smaller PDFs from the same generator pass. So The document has no pages appears to be a generic upstream parser/ingestion failure at this complexity boundary, not a literal statement about the file.

Finding 3: a tiny PDF can fail from page count alone

To isolate page count from byte size and text density, I generated sparse PDFs: many pages, very little text per page.

Google Vertex + Gemini 3.1 Pro + OpenRouter native PDF:

SizePagesResult
0.07 MiB100pass
0.36 MiB500pass
0.71 MiB1,000pass
1.07 MiB1,500fail: The document contains 1500 pages which exceeds the supported page limit of 1000.

This is the cleanest result in the whole experiment.

A 1 MiB PDF failed because it had too many pages. Meanwhile, a 100 MiB padded PDF passed because most of the bytes were irrelevant to the parser.

So “file size” is clearly not the right user-facing abstraction.

Finding 4: Gemini Files API accepts large files, but that is not the same as generation success

Google recommends Gemini Files API for larger PDFs and reusable documents. I tested whether uploading to Files API first would make large PDFs work.

The AI Studio key worked for Files API. A 1 MiB PDF uploaded, became ACTIVE, and generated successfully with direct Gemini:

state=ACTIVE
uri=https://generativelanguage.googleapis.com/v1beta/files/...
direct PASS text="OPENROUTER_PDF_OK"

Then I tried larger dense-text pdf-lib PDFs:

FileFiles API uploadGeneration result
10 MiB / 450 pagesACTIVEfail: input token count exceeds max
15 MiB / 675 pagesACTIVEfail: input token count exceeds max
50 MiB / 2,250 pagesACTIVEfail: invalid argument

The 50 MiB file is especially clarifying. The upload succeeded:

{
  "mimeType": "application/pdf",
  "sizeBytes": "52434249",
  "state": "ACTIVE",
  "source": "UPLOADED"
}

But generation failed.

So Gemini Files API’s 50 MB support is an admission/storage capability. It does not guarantee that the model can successfully use the uploaded PDF in a generation request. Page count, context, and rendering/tokenization still matter.

I also tried passing a Gemini Files API URI into OpenRouter. That failed with:

403 PERMISSION_DENIED
You do not have permission to access the File ... or it may not exist.

My interpretation: Files API URIs are scoped to the Google project/auth that uploaded them. OpenRouter’s upstream Google request cannot access a file uploaded with my local key unless OpenRouter is actually using that same upstream auth context.

Finding 5: providers fail differently

The whole point of a model router is that provider routes vary. PDF handling is no exception.

Anthropic

OpenRouter → Claude Sonnet 4.5 → Anthropic, using padded transport-control PDFs:

SizeResult
30 MiBpass
32 MiBfail: The file exceeds the maximum allowed size.

Anthropic exposed a clearer provider admission limit around 32 MiB in this route.

OpenAI

OpenRouter → GPT-5.4 Nano → OpenAI, using padded transport-control PDFs:

SizeResult
50 MiBpass
75 MiBfail: File urls cannot be larger than 32MB.
100 MiBfail: File urls cannot be larger than 32MB.

The 50 MiB pass plus 75/100 MiB “32MB” failures need follow-up with real PDF families. But they reinforce the broader lesson: provider-specific file paths have their own behavior, and the error messages are not always straightforward.

What this means for builders

If users upload PDFs into your app, do not expose one number and hope it maps to reality.

A better product model is:

upload → preflight → user-facing verdict

The preflight step should answer three practical questions:

  1. Can I send this file as one native PDF request?
  2. If not, what should I tell the user?
  3. Which failure should I prevent before the user waits for a doomed request?

Figure 3: a user-facing verdict chart

Turn PDF complexity into a small set of user-visible verdictsThe user should not have to understand file admission, parser failures, page gates, or context windows.Likely to work≤10 MiB and ≤450 normal pagesSend as native PDF with confidence.Check first10–15 MiB or 450–650 dense pagesNear observed timeout/failure zone.Likely to fail>15 MiB dense PDF or parser-risky fileDo not let the user wait on one request.Too many pagesObserved hard gate: >1,000 pagesCan fail even around 1 MiB.Upload ≠ usableGemini Files API accepted ~50 MiBGeneration still failed.Provider-specificAnthropic rejected ~32 MiB padded PDFsOther routes need their own profile.Synthesize this for users as:“Likely to work” · “We need to check this PDF” · “This PDF is too many pages” · “This route probably cannot process this file”That is more accurate and more actionable than “max 50 MB.”

The key product move is to turn uncertainty into a verdict. The user does not need to understand parser limits or context windows; they need to know whether this file is likely to work, needs a compatibility check, or should be rejected before a doomed model call.

The upload statuses I would actually show

StatusWhen to show itCopy
Likely to worksmall, normal PDF within safe route limits“This PDF is likely to work with the selected model.”
Check requirednear observed route boundary“This PDF is near provider limits. We need to check it before continuing.”
Too many pagesexceeds hard page limit“This PDF has too many pages for the selected model route.”
Too large / too complexexceeds observed reliable zone“This PDF is unlikely to work as one native PDF request.”
Cannot readencrypted/corrupt/unparseable“Upload an unlocked or re-exported copy.”
Upload onlyFiles API accepted it, but generation is risky“The file uploaded, but that does not guarantee the model can use it.”

What to inspect

At minimum, compute:

type PdfProfile = {
  bytes: number;
  pages: number;
  encrypted: boolean;
  hasText: boolean;
  textChars: number;
  estimatedTextTokens: number;
  isProbablyScanned: boolean;
  images?: {
    count: number;
    pagesWithLargeImages: number;
  };
  parseWarnings: string[];
};

Then compare that profile against the route you intend to use:

type PdfRouteProfile = {
  routeId: string;
  label: string;
  hardLimits: {
    maxBytes?: number;
    maxPages?: number;
  };
  softLimits: {
    directBytesSafe?: number;
    directPagesSafe?: number;
    timeoutRiskPages?: number;
  };
};

From the current data, I would start Gemini Vertex native PDF conservatively:

const geminiVertexNativePdf = {
  routeId: 'openrouter:google/gemini-3.1-pro-preview:google-vertex:native-pdf',
  label: 'Gemini 3.1 Pro via Google Vertex',
  hardLimits: {
    maxPages: 1000,
    maxBytes: 50 * 1024 * 1024,
  },
  softLimits: {
    directBytesSafe: 10 * 1024 * 1024,
    directPagesSafe: 450,
    timeoutRiskPages: 550,
  },
};

Those are not universal truths. They are operational guardrails for this route based on the observed corpus.

What to tell users

Do not say:

Max PDF size: 50 MB.

Say something closer to:

We check every PDF before processing. Small PDFs are read directly. Larger PDFs are split, indexed, or OCR’d depending on their structure. Some providers also enforce page-count limits.

Then show a concrete plan.

Ready

Ready for direct reading
4.2 MB · 38 pages
This PDF can be read directly by Gemini.

Large but processable

Large PDF
18.7 MB · 620 pages

This is too large for one reliable direct model call. We'll split it into sections and answer from the relevant parts.

Needs conversion

Needs OCR
12.1 MB · 90 scanned pages

Native model reading may be unreliable. We'll OCR the document first, then answer from extracted text.

Too large for selected route

Too many pages for Gemini native PDF
1.1 MB · 1,500 pages

The selected route supports up to 1,000 pages. This file is very likely to fail.

Compatibility check required

Near provider limits
13.4 MB · 608 pages

This PDF is near the known reliability boundary for Gemini native PDF reading. It may fail or time out.

So what files can I send?

For the route I tested most carefully — OpenRouter → Gemini 3.1 Pro → Google Vertex → native PDF — I would summarize the current evidence like this:

File shapeSend as one native PDF request?Why
≤10 MiB and ≤450 normal/dense text pagesYes, likelyPassed in this corpus with margin.
11–13 MiB and 500–600 dense text pagesMaybeSome passed, but this is near the noisy boundary.
14–15 MiB and 650–675 dense text pagesRisky / likely noTimeouts and parser failures appeared here.
50 MiB dense text PDFNoFiles API upload can succeed, but generation failed; OpenRouter native route failed too.
≤1,000 sparse pagesYes, page-count-wiseSparse 1,000-page PDF passed.
>1,000 pagesNo for this routeExplicit provider error: supported page limit of 1,000.
Padded bytes after %%EOFNot representative100 MiB passed, but only as a transport probe.
Anthropic native PDF around 32 MiBNo in this routeProvider rejected with file-size error.

That table is the most practical output of the experiment. It is intentionally route-specific. Change the provider route, and you should assume the table changes.

How do I know if a PDF will fail?

You cannot know from file size alone. But you can catch most doomed cases before sending the model request.

Check these fields before calling OpenRouter:

FieldWhy it mattersUser-visible consequence
bytesSome routes reject large file objects or URLs.“This file is too large for the selected route.”
page countGemini/Vertex showed an explicit 1,000-page gate.“This PDF has too many pages.”
text densityDense PDFs hit parser/context/timeout boundaries earlier.“This PDF is near the reliability boundary.”
scanned/image-heavy pagesByte size may understate visual processing cost.“This PDF needs extra checking.”
encryption/corruptionThe route may not parse it at all.“Upload an unlocked or re-exported copy.”
provider routeAnthropic, OpenAI, Google Vertex, and Google AI Studio differ.“This file may work with one provider and fail with another.”

For users, synthesize all of that into a small number of verdicts:

VerdictMeaning
Likely to workWithin the route’s observed safe zone.
Needs compatibility checkNear the observed boundary; may timeout or fail.
Too many pagesExceeds an explicit page cap.
Too large or complexPast the route’s observed reliable zone.
Cannot read this PDFEncrypted, corrupt, or metadata cannot be parsed.

How do I prevent failures?

Prevent the failures you can classify cheaply:

  1. Reject obvious hard-limit violations before model calls. For Gemini/Vertex native PDF, do not send a >1,000-page PDF as one file.
  2. Treat advertised upload limits as admission limits. Gemini Files API accepting a 50 MiB PDF does not mean generation will work.
  3. Keep a per-route safe zone. For Gemini/Vertex native PDF, this experiment suggests “likely to work” should start around ≤10 MiB and ≤450 dense pages, not 50 MiB.
  4. Show uncertainty explicitly near the boundary. A 13–15 MiB dense PDF is not a clean yes/no; call it “needs compatibility check.”
  5. Log failures by layer. “PDF failed” is useless. “page_count_limit,” “provider_file_size_limit,” “parser_failure,” and “context_limit” tell you how to improve your user-facing verdicts.

What changed my mind

Before running the experiments, I expected to find a rough OpenRouter-side file-size threshold. I now think that framing is too coarse.

The decisive observations were:

Those four facts cannot be explained by one file-size limit. They require a pipeline model.

Downloadable artifacts

The generated PDFs are public so readers can rerun or falsify the tests.

Public prefix:

https://pub-e68ba3382809416cb3ae5ad57c5ff6e4.r2.dev/openrouter-file-limits

Useful standards-compliant dense-text artifacts:

ArtifactSizePages
openrouter-pdflib-pdf-limit-1mib.pdf~1 MiB50
openrouter-pdflib-pdf-limit-10mib.pdf~10 MiB450
openrouter-pdflib-pdf-limit-13mib.pdf~13 MiB600
openrouter-pdflib-pdf-limit-15mib.pdf~15 MiB675
openrouter-pdflib-pdf-limit-50mib.pdf~50 MiB2,250

Sparse-page artifacts:

ArtifactSizePages
openrouter-sparse-pages-100pages.pdf~0.07 MiB100
openrouter-sparse-pages-500pages.pdf~0.36 MiB500
openrouter-sparse-pages-1000pages.pdf~0.71 MiB1,000
openrouter-sparse-pages-1500pages.pdf~1.07 MiB1,500

Conclusion

A model router can normalize request shape, routing, and billing. It cannot make every upstream provider’s document ingestion pipeline behave the same way.

For PDFs, the meaningful limit is not “MB.” It is the first failing layer among transport, file admission, parsing, page count, rendering/tokenization, model context, and generation.

So if you are building with PDF uploads, the action item is not to find one magic maximum. The action item is to build a preflight system that turns a messy PDF into a concrete processing plan.