Root field pdf_preprocess

When POST /v1/chat/completions messages contain a parseable PDF (validated input_file in a user message, normalized internally to a file part with file_data / file_id / file_url), this service may preprocess the PDF before forwarding upstream.

Default behavior (important)

  • Omit root pdf_preprocess, or pass an object without engine: both mean nativeno expansion; keep the file part for upstream (model must support native PDF input).
  • engine only fails validation on invalid values (400 / invalid body).
  • false / null: disables the preprocess config object (exact semantics vs “omit object” follow the README).

engine values

engineBehavior
nativeNo expansion; keep normalized file part.
ocrReplace the PDF part with per-page JPEG image_url (data URLs); no [PDF] meta line or full text layer; user text in the same user message is kept.
markdownMeta text + Markdown-style text from the PDF text layer (no complex layout fidelity).

Optional parameters

  • max_pages: defaults and caps in pdf-preprocess/constants (README summary; typical default 10, cap 50 order of magnitude).
  • merge_pages: when true, affects ocr rendering only (merge pages vertically into one JPEG).

Runtime and ops

  • WASM: env GATEWAY_PDFIUM_WASM_PATH points to pdfium.wasm; if unset, try @embedpdf/pdfium package path (depends on cwd—set explicitly in production).
  • Preprocess failures may return 4xx / 504 with error.code such as pdf_password_required, pdf_expand_too_large, etc.—full list and size/timeout limits in the README and constants source.

SDK mapping

Put config in chatRequest.plugins.pdf; @routerbrain/sdk serializes it to JSON root pdf_preprocess—see SDK: chat.send.

See also

Back to docs home