extract.chunks
Split a PDF into structure-aware chunks for retrieval, with stable ids.
POST /v1/extract/chunks
| Input | one file, sent as multipart/form-data; the optional options part is a JSON object |
| Output | JSON |
| Credits | credits per page by quality: fast 1, auto 3 |
| Limits | [size, page and time limits: no claim ID yet] |
| Reads or changes the document | reads only |
| Error statuses | 400, 413, 422, 500, 501, 504 (see Errors) |
Options
Section titled “Options”| Option | Type | Required | Default | Description |
|---|---|---|---|---|
chunking_strategy |
string | no | How chunks are formed. Default structure. structure: The engine’s structure-aware chunker: headings, lists and tables drive the splits. The default, and what this operation did before the strategies below existed. basic: Pack elements in reading order up to the budget. Tables stand alone. by_title: A new chunk starts at every title; small sections can be combined. by_page: A new chunk starts at every page. |
|
combine_text_under_n_chars |
integer | no | 0 |
by_title and by_page: merge sections shorter than this with the next one, within max_characters. Default 0 (off). |
max_characters |
integer | no | 1500 |
Most Unicode characters in a chunk. Default 1500. |
multipage_sections |
boolean | no | true |
by_title: let a section run across a page boundary. Default true. |
new_after_n_chars |
integer | no | Close a chunk once it has this many characters (basic, by_title, by_page). Default: max_characters. |
|
overlap |
integer | no | 100 |
Characters shared between neighbouring chunks of one split element. Default 100. |
pages |
array of integer | no | One-based pages. Default: all pages. | |
password |
string | no | Password of an encrypted document. | |
quality |
string | no | Extraction quality tier. Default fast. fast: Geometric extraction, no model, no OCR. The default. auto: fast plus OCR of scanned pages. Answers quality_unavailable (501) on a deployment without an OCR engine; it never reads fast in its place. |
Example
Section titled “Example”curl -sS -f -X POST "$PDFLUENT_API_URL/v1/extract/chunks" \ -H "x-api-key: $PDFLUENT_API_KEY" \ -F 'options={"max_characters":500}' \ -o result.jsonimport jsonimport os
import requests
options = {"max_characters": 500}
parts = [ ("file", ("structured.pdf", open("structured.pdf", "rb"))), ("options", (None, json.dumps(options))),]
response = requests.post( os.environ["PDFLUENT_API_URL"] + "/v1/extract/chunks", headers={"x-api-key": os.environ["PDFLUENT_API_KEY"]}, files=parts,)response.raise_for_status()
with open("result.json", "wb") as out: out.write(response.content)import { openAsBlob } from 'node:fs';import { writeFile } from 'node:fs/promises';
const form = new FormData();form.append('file', await openAsBlob("structured.pdf"), "structured.pdf");form.append('options', JSON.stringify({"max_characters":500}));
const response = await fetch(process.env.PDFLUENT_API_URL + "/v1/extract/chunks", { method: 'POST', headers: { 'x-api-key': process.env.PDFLUENT_API_KEY }, body: form,});if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
await writeFile("result.json", Buffer.from(await response.arrayBuffer()));The key goes in the x-api-key header; see Authentication. Every response carries x-pdfluent-pages and x-pdfluent-credits.