You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 358e21a
Browse filesBrowse the repository at this point in the historyBrowse files
fix: set elements_file even when the server returns JSON
The deployed API does not offer application/x-ndjson -- its spec (v1.5.69) declares
only application/json and text/csv, and the string "ndjson" appears nowhere in the
document. So any request that bypasses the split-PDF hook came back as JSON, the
application/json branch matched first and won, and elements_file stayed None while
elements was populated. The opt-in was silently ignored.
That path is much wider than "non-PDF". _before_request_unlocked short-circuits when
split_size >= page_count, and get_optimal_split_size floors at MIN_PAGES_PER_SPLIT=2,
so one- and two-page PDFs are sent whole -- it would have read as intermittent to
anyone hitting it on small inputs.
The x-ndjson branch is now checked first, and a JSON body is written out as NDJSON
when NDJSON was requested. elements_file is therefore set for every input and
callers need one code path rather than two. This does not bound memory on the
unsplit path -- the body is already read and parsing adds the element list on top --
it makes the contract uniform. The memory win remains the split-PDF path, where the
hook concatenates chunk files on disk and this conversion is never reached.
Also fixes the README example, which raised TypeError from open(None) and then
raised the same TypeError again out of Path(None) in the finally, masking the first.
Adds the end-to-end coverage whose absence let this through: all 24 existing tests
were helper- or hook-level, so nothing exercised the media-type dispatch in
general.py. Three tests now drive partition() over a mock transport -- server
returns JSON, server returns NDJSON, and no override at all. The first fails against
the old dispatch. They hold the client for the call rather than chaining off a
temporary, since sdk.py registers a weakref.finalize that closes the transport.
Smaller review notes: log a warning per skipped empty chunk so element_count can be
reconciled against chunk_count; document that the non-"[" sniff assumes one JSON
value per line rather than checking; trim the _combine_chunks_to_ndjson docstring.
The regeneration comments no longer claim a daily workflow is about to drop the
field -- generation is blocked at the Speakeasy account level and gen.lock has not
moved since 2026-01. Whether that scaffolding is worth keeping is left open.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
## 0.46.0
2
2
3
3
### Features
4
-
* Add an NDJSON elements-file mode to `partition()`. Pass `accept_header_override=PartitionAcceptEnum.APPLICATION_X_NDJSON` to get `PartitionResponse.elements_file` — a path to an NDJSON file with one element per line — instead of `PartitionResponse.elements`. On the split-PDF path the per-chunk temp files are concatenated on disk rather than parsed, flattened, re-serialized with `json.dumps` and re-parsed by the SDK, which held four copies of the document in memory at once. Peak memory becomes roughly one chunk instead of the whole document. **The caller owns the returned file and is responsible for deleting it.** Requesting `application/json` (the default) is unchanged.
4
+
* Add an NDJSON elements-file mode to `partition()`. Pass `accept_header_override=PartitionAcceptEnum.APPLICATION_X_NDJSON` to get `PartitionResponse.elements_file` — a path to an NDJSON file with one element per line — instead of `PartitionResponse.elements`. On the split-PDF path the per-chunk temp files are concatenated on disk rather than parsed, flattened, re-serialized with `json.dumps` and re-parsed by the SDK, which held four copies of the document in memory at once; peak memory becomes roughly one chunk instead of the whole document. `elements_file` is set for every input, including ones that are not split and responses from a server that ignores the `Accept` header, so callers need only one code path — but the memory saving itself applies only to split PDFs (a PDF of more than two pages, with `split_pdf_page=True`). **The caller owns the returned file and is responsible for deleting it.** Requesting `application/json` (the default) is unchanged.
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -434,7 +434,7 @@ For very large documents, the parsed element list can dominate the client's memo
434
434
**You own the returned file and are responsible for deleting it.**
435
435
436
436
> [!NOTE]
437
-
> The memory savingapplies to the split-PDF path, i.e. a PDF with `split_pdf_page=True` (the default). For unsplit inputs — a non-PDF file, or `split_pdf_page=False` — the response body is still read fully into memory before being written to disk, so peak memory can reach roughly twice the body size. You still get `elements_file` either way.
437
+
> `elements_file` is always set when you pass this header, but the **memory saving** only applies to the split-PDF path. An input is only split when it is a PDF, `split_pdf_page=True` (the default), and it has more than two pages — `split_size` is floored at 2, so one- and two-page PDFs are sent whole. For those, and for non-PDFs, the response body is read fully into memory before being written to disk, so peak memory can reach roughly twice the body size.
0 commit comments