← All Labs Lab 26 / 28 PDF extraction through Mycel and the egress proxy
Lab 26 · Run models · Built

PDF extraction through Mycel and the egress proxy

The same PDFs go to models through Mycel and to web extractors through the egress proxy, with no vendor key in the lab, and every extractor is scored by recall of the same answer-key facts.

Built Needs: chat Smoke: pnpm exec tsx examples/26-pdf-extraction/run.ts --smoke Run: pnpm exec tsx examples/26-pdf-extraction/run.ts --live Source: examples/26-pdf-extraction

Which extractor gets the facts out of a PDF? This lab sends the same three PDFs to every extractor and counts how many of the facts in cases.ts each one's output states. It runs two kinds of extractor:

  • Models get the PDF bytes as an OpenAI file content part on Mycel's /v1/chat/completions.
  • Web extractors get the PDF's public URL at their real API host, with no key. These are Firecrawl /v2/scrape, Exa /contents and Parallel /v1/extract. The Lab 05 egress proxy adds the keys.

The lab process holds no vendor key and refuses to start with one in its environment (D-28).

sh
pnpm exec tsx examples/26-pdf-extraction/run.ts --smoke    # offline: fake Mycel and fake vendors, 5 checks
pnpm exec tsx examples/26-pdf-extraction/run.ts --live     # Gemini 4 Hydrogen and Claude Haiku 5.5 through Mycel
pnpm exec tsx examples/26-pdf-extraction/run.ts --live --models z-ai/glm-5.3-flash,moonshotai/kimi-k3.1-pro
pnpm exec tsx examples/26-pdf-extraction/run.ts --live --models deepseek/deepseek-v4.1-flash --pdf-engine mistral-ocr

--live needs MYCEL_API_KEY. MYCEL_URL defaults to https://mycel.thefocus.ai and MYCEL_END_USER to lab-26. Results go to --out, which defaults to output/pdf-extraction/results.json.

Adding the web extractors

Start the Lab 05 proxy with the vendor keys in its environment, not this one. Then point this lab at it:

sh
HTTPS_PROXY=http://lab26:<token>@127.0.0.1:7453 NODE_USE_ENV_PROXY=1 NODE_EXTRA_CA_CERTS=<proxy-ca.pem> \
  pnpm exec tsx examples/26-pdf-extraction/run.ts --live

Web extractors fetch the PDF themselves, so it must be public. --pdf-base-url defaults to the fixtures on GitHub main.

The PDF engine

Mycel's upstream parses a PDF before the model sees it unless the request says otherwise. A text-only model then "reads" a scanned receipt through the upstream's OCR. So the lab pins OpenRouter's file-parser plugin, which Mycel passes through, with --pdf-engine:

  • native (the default): the model reads the PDF itself.
  • pdf-text or mistral-ocr: the upstream parses it first.
  • auto: the upstream decides.

The fixtures

fixtures/ holds each PDF next to the HTML it was printed from, made with google-chrome --headless --print-to-pdf. There are 19 facts in all:

PDFWhat makes it hardFacts
invoice.pdfA text PDF with a line-item table.6
receipt.pdfA scan: a noisy, rotated JPEG with no text layer.6
report.pdfTwo pages, with a table on page 2 and a footnote.7

To rebuild the scan, take a screenshot of receipt.html, then add noise with magick … -rotate 1.2 +noise Gaussian. Print a page holding only that image with Chrome. ImageMagick's own PDF output came out blank to the models.

Matching ignores case, whitespace, commas, currency signs and Markdown punctuation. A table-row fact such as "Valley 1.41M 4" therefore matches a Markdown row, but only when its cells come out in order.

Checks

CheckWhat it proves
recall-matches-hand-countA hand-written transcription scores the 5 of 6 facts counted by hand, and swapping two cells loses the row fact.
pdf-reaches-mycelEach of the 6 Mycel requests carries the fixture's exact bytes as a file part, an end user, and engine native.
no-vendor-key-sent9 vendor requests reach the real paths with no authorization or x-api-key header, and each names the fixture URL.
ranks-by-recallRows sort by mean recall, and the mean matches a hand-computed value of (1 + 1 + 6/7) / 3. A failing vendor's errors are kept on each cell.
refuses-vendor-keysAn environment holding EXA_API_KEY is refused, and MYCEL_API_KEY is allowed.

Break it

In mycelExtractor in run.ts, replace the file part with a text note naming the PDF. pdf-reaches-mycel fails at 0/6, ranks-by-recall fails, and the smoke exits 1.

Files

  • run.ts: the extractors, the scoring and the smoke.
  • cases.ts: the answer key and the matcher.
  • fixtures/: the PDFs and their HTML sources.
  • PROMPT.md: the prompt to rebuild this lab.
  • FINDINGS.md: what we learned.

Prompt

Coding-Agent Prompt · Ready to Paste
Build `examples/26-pdf-extraction/`: a lab that sends the same PDFs to every extractor, models through Mycel and web extractors (Firecrawl, Exa, Parallel) through the Lab 05 egress proxy, and scores each by recall of the same answer-key facts. The lab process holds no vendor key (D-28).

Read first: `examples/05-zero-key-agents/README.md` (how agents reach vendor hosts through HTTPS_PROXY with no key, and the vendor request shapes in its tools.ts) and `examples/20-system-one-decisions/run.ts` (Mycel auth: Bearer MYCEL_API_KEY plus an `x-mycel-end-user` header; the fake-Mycel smoke pattern). Do not import from other example folders.

1. `fixtures/`: three PDFs printed with headless Chrome from HTML kept beside them: a text invoice with a line-item table, a scanned receipt (screenshot, noise and rotation, printed as an image-only page), and a two-page report with a table on page 2 and a footnote.
2. `cases.ts`: the facts each PDF states, with accepted spellings, and a matcher that ignores case, whitespace, commas, currency signs and Markdown punctuation, so table-row facts match only when their cells come out in order.
3. Model extractors: POST `${MYCEL_URL}/v1/chat/completions` with the PDF as `{ type: "file", file: { filename, file_data: "data:application/pdf;base64,…" } }` and a "convert to Markdown, keep every number" prompt. Pin `plugins: [{ id: "file-parser", pdf: { engine } }]`, `native` by default (`--pdf-engine`), because the upstream otherwise parses or OCRs the PDF for the model.
4. Web extractors: POST the real hosts (api.firecrawl.dev/v2/scrape, api.exa.ai/contents, api.parallel.ai/v1/extract) with the PDF's public URL (`--pdf-base-url`) and no credentials. Include them in --live only when HTTPS_PROXY and NODE_USE_ENV_PROXY=1 are set. Refuse to start when a vendor key variable is in the environment.
5. `--live`: Gemini 4 Hydrogen and Claude Haiku 5.5 by default (`--models a,b`); print and save a ranking by mean recall with per-PDF recall, missed facts and errors.
6. `--smoke` (and the default): fake Mycel and fake vendors on loopback. Checks, one PASS/FAIL line each, exit 1 on any failure: recall-matches-hand-count (a hand-written transcription, counted by hand), pdf-reaches-mycel (exact bytes, end user, engine), no-vendor-key-sent, ranks-by-recall (against a hand-computed mean), refuses-vendor-keys.
7. Strict TypeScript, no `any`; close servers in `finally`. README with frontmatter, a check table and a Break it section, and FINDINGS.md.
Works in Pi, Claude Code, Codex & Antigravity Offline mock first → --live opt-in

What we learned

The answer so far

Models only, from the 2026-12-01 live run with --pdf-engine native (each model reads the PDF itself):

Model (through Mycel)invoicereceipt (scan)reportmeantime per PDF
anthropic/claude-haiku-5.5100%100%100%100%1.8–2.3 s
google/gemini-4-hydrogen100%100%100%100%4.4–11.0 s
moonshotai/kimi-k3.1-pro100%100%100%100%12.6–48.5 s
z-ai/glm-5.3-flash100%100%100%100%4.4–6.6 s
deepseek/deepseek-v4.1-flash0%0%0%0%3.4–6.8 s

Every PDF-capable model got all 19 facts, so these fixtures separate models that can read a PDF from ones that can't, but they don't rank the models that can. Harder fixtures are the next step: multi-column layouts, rotated tables, handwriting, and long documents where a fact sits on page 30.

Findings

  • The upstream reads PDFs for the model unless told not to. Without a pinned engine, DeepSeek V4.1 Flash, a text-only model, got 100% on the scanned receipt. Pinning native dropped it to 0%: it answered in 55–196 characters that it saw no document. With pdf-text, neither DeepSeek nor Haiku could read the scan, which has no text layer. An unpinned run therefore scores the upstream's parser, not the model.
  • Mycel passes plugins through. OpenRouter's file-parser plugin reached the upstream unchanged, as Lab 22 found for other unadvertised parameters. This depends on Mycel's current supplier being OpenRouter, and a different supplier may ignore it.
  • The catalog can't find PDF readers. Hydrogen and Haiku are listed as chat only, with no capability for file or PDF input, so --live names its models instead of filtering the catalog the way Lab 20 does.
  • Haiku was the cheapest and fastest here. The first invoice probe cost $0.00028 on Haiku and $0.0024 on Hydrogen, and Hydrogen spent about 100 reasoning tokens on it.
  • ImageMagick wrote a scan PDF that models saw as blank. The orb has no Ghostscript, and the PDF magick produced came back as "The PDF page appears to be blank" from Haiku. Printing a page that holds only the scan image with Chrome fixed it.
  • Mycel needs x-mycel-end-user. A chat request with only the bearer token gets 401 unauthorized.

Not tested yet

  • Firecrawl, Exa and Parallel. No vendor keys exist in this orb, and the Lab 05 proxy is not deployed anywhere, so the web extractors have only run against the smoke's fakes. They also need the fixtures to be public. The default URL points at GitHub main, so they can't run until this lab is merged.
  • Perplexity and Clairic (named in D-33) are not wired. Perplexity is a model, not a page extractor, so it belongs on Mycel's catalog rather than the proxy. Clairic's API isn't known here yet.
  • Router parsers as extractors. --pdf-engine mistral-ocr or pdf-text runs them, but they weren't compared in a full live run.
  • Cost per PDF. Usage comes back on every response, but the lab doesn't record it yet.

Smoke run

Visual Target Wireframe ASCII Layout
  PASS  recall-matches-hand-count: transcript finds 5/6, misses [VAT line]; with two cells swapped, misses [wrench row, VAT line]
  PASS  pdf-reaches-mycel: 6/6 Mycel requests carried the fixture's exact bytes as a file part, an end user and engine "native"
  PASS  no-vendor-key-sent: 9 vendor requests, 0 with an authorization or x-api-key header; each names a fixture URL
  PASS  ranks-by-recall: order fake/full,firecrawl,fake/no-footnote,exa,parallel; no-footnote mean 0.9524 (expected 0.9524); parallel errors kept per cell
  PASS  refuses-vendor-keys: an env with EXA_API_KEY and MYCEL_API_KEY is refused for [EXA_API_KEY]