33from __future__ import annotations
44
55import os
6+ from typing_extensions import Literal
67
78import httpx
89
@@ -59,14 +60,83 @@ def handle(
5960 self ,
6061 body : FileContent | BinaryTypes ,
6162 * ,
62- base_url : str | Omit = omit ,
63- extension : str | Omit = omit ,
64- filename : str | Omit = omit ,
63+ extension : Literal [
64+ "txt" ,
65+ "text" ,
66+ "md" ,
67+ "markdown" ,
68+ "html" ,
69+ "htm" ,
70+ "xhtml" ,
71+ "xml" ,
72+ "rss" ,
73+ "atom" ,
74+ "csv" ,
75+ "tsv" ,
76+ "yaml" ,
77+ "yml" ,
78+ "py" ,
79+ "java" ,
80+ "js" ,
81+ "jsx" ,
82+ "mjs" ,
83+ "cjs" ,
84+ "json" ,
85+ "jsonl" ,
86+ "ndjson" ,
87+ "php" ,
88+ "sh" ,
89+ "bash" ,
90+ "zsh" ,
91+ "fish" ,
92+ "rb" ,
93+ "ts" ,
94+ "tsx" ,
95+ "rtf" ,
96+ "srt" ,
97+ "css" ,
98+ "scss" ,
99+ "less" ,
100+ "styl" ,
101+ "sass" ,
102+ "svg" ,
103+ "pdf" ,
104+ "docx" ,
105+ "doc" ,
106+ "xlsx" ,
107+ "xlsm" ,
108+ "xlsb" ,
109+ "xltx" ,
110+ "xltm" ,
111+ "xls" ,
112+ "pptx" ,
113+ "pptm" ,
114+ "ppsx" ,
115+ "ppsm" ,
116+ "potx" ,
117+ "potm" ,
118+ "ppt" ,
119+ "pps" ,
120+ "pot" ,
121+ "jpg" ,
122+ "jpeg" ,
123+ "jpe" ,
124+ "png" ,
125+ "gif" ,
126+ "bmp" ,
127+ "tiff" ,
128+ "tif" ,
129+ "webp" ,
130+ "ppm" ,
131+ "pbm" ,
132+ "pgm" ,
133+ "pnm" ,
134+ ]
135+ | Omit = omit ,
65136 include_images : bool | Omit = omit ,
66137 include_links : bool | Omit = omit ,
67138 ocr : bool | Omit = omit ,
68- pdf_end : int | Omit = omit ,
69- pdf_start : int | Omit = omit ,
139+ pdf : parse_handle_params .Pdf | Omit = omit ,
70140 shorten_base64_images : bool | Omit = omit ,
71141 use_main_content_only : bool | Omit = omit ,
72142 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -78,30 +148,28 @@ def handle(
78148 ) -> ParseHandleResponse :
79149 """
80150 Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes
81- into LLM-usable Markdown.
151+ into LLM-usable Markdown. The base request costs 1 credit. When OCR runs
152+ (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no
153+ OCR ends up running still cost 1 credit.
82154
83155 Args:
84- base_url: Optional HTTP(S) source document URL used to resolve relative links and image
85- references. Relative references remain relative when omitted.
86-
87- extension: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv,
88- md, py, rtf, jpg, png, or txt.
89-
90- filename: Optional filename hint used to infer the extension when extension is omitted.
156+ extension: Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g.
157+ ".pdf").
91158
92159 include_images: Include image references in Markdown output
93160
94161 include_links: Preserve hyperlinks in Markdown output
95162
96- ocr: When true for PDF inputs, detect and OCR images embedded in the selected pages,
97- inserting recognized text at each image's position in page reading order while
98- preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range.
99- This is separate from automatic scanned-PDF OCR fallback.
100-
101- pdf_end: Last 1-based PDF page to parse. When omitted, parsing ends at the last page.
102- Must be greater than or equal to pdfStart when both are provided .
163+ ocr: Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted
164+ at each image's position in page reading order, preserving the text layer;
165+ pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get
166+ full-document OCR, and raster images get their visible text transcribed. When
167+ false, no OCR runs: scanned PDFs may yield no content and images return only
168+ format/dimension metadata. Calls where OCR actually runs cost 5 credits instead
169+ of 1 .
103170
104- pdf_start: First 1-based PDF page to parse. When omitted, parsing starts at the first page.
171+ pdf: PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true)
172+ to an inclusive 1-based page range.
105173
106174 shorten_base64_images: Shorten base64-encoded image data in the Markdown output
107175
@@ -126,14 +194,11 @@ def handle(
126194 timeout = timeout ,
127195 query = maybe_transform (
128196 {
129- "base_url" : base_url ,
130197 "extension" : extension ,
131- "filename" : filename ,
132198 "include_images" : include_images ,
133199 "include_links" : include_links ,
134200 "ocr" : ocr ,
135- "pdf_end" : pdf_end ,
136- "pdf_start" : pdf_start ,
201+ "pdf" : pdf ,
137202 "shorten_base64_images" : shorten_base64_images ,
138203 "use_main_content_only" : use_main_content_only ,
139204 },
@@ -168,14 +233,83 @@ async def handle(
168233 self ,
169234 body : FileContent | AsyncBinaryTypes ,
170235 * ,
171- base_url : str | Omit = omit ,
172- extension : str | Omit = omit ,
173- filename : str | Omit = omit ,
236+ extension : Literal [
237+ "txt" ,
238+ "text" ,
239+ "md" ,
240+ "markdown" ,
241+ "html" ,
242+ "htm" ,
243+ "xhtml" ,
244+ "xml" ,
245+ "rss" ,
246+ "atom" ,
247+ "csv" ,
248+ "tsv" ,
249+ "yaml" ,
250+ "yml" ,
251+ "py" ,
252+ "java" ,
253+ "js" ,
254+ "jsx" ,
255+ "mjs" ,
256+ "cjs" ,
257+ "json" ,
258+ "jsonl" ,
259+ "ndjson" ,
260+ "php" ,
261+ "sh" ,
262+ "bash" ,
263+ "zsh" ,
264+ "fish" ,
265+ "rb" ,
266+ "ts" ,
267+ "tsx" ,
268+ "rtf" ,
269+ "srt" ,
270+ "css" ,
271+ "scss" ,
272+ "less" ,
273+ "styl" ,
274+ "sass" ,
275+ "svg" ,
276+ "pdf" ,
277+ "docx" ,
278+ "doc" ,
279+ "xlsx" ,
280+ "xlsm" ,
281+ "xlsb" ,
282+ "xltx" ,
283+ "xltm" ,
284+ "xls" ,
285+ "pptx" ,
286+ "pptm" ,
287+ "ppsx" ,
288+ "ppsm" ,
289+ "potx" ,
290+ "potm" ,
291+ "ppt" ,
292+ "pps" ,
293+ "pot" ,
294+ "jpg" ,
295+ "jpeg" ,
296+ "jpe" ,
297+ "png" ,
298+ "gif" ,
299+ "bmp" ,
300+ "tiff" ,
301+ "tif" ,
302+ "webp" ,
303+ "ppm" ,
304+ "pbm" ,
305+ "pgm" ,
306+ "pnm" ,
307+ ]
308+ | Omit = omit ,
174309 include_images : bool | Omit = omit ,
175310 include_links : bool | Omit = omit ,
176311 ocr : bool | Omit = omit ,
177- pdf_end : int | Omit = omit ,
178- pdf_start : int | Omit = omit ,
312+ pdf : parse_handle_params .Pdf | Omit = omit ,
179313 shorten_base64_images : bool | Omit = omit ,
180314 use_main_content_only : bool | Omit = omit ,
181315 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -187,30 +321,28 @@ async def handle(
187321 ) -> ParseHandleResponse :
188322 """
189323 Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes
190- into LLM-usable Markdown.
324+ into LLM-usable Markdown. The base request costs 1 credit. When OCR runs
325+ (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no
326+ OCR ends up running still cost 1 credit.
191327
192328 Args:
193- base_url: Optional HTTP(S) source document URL used to resolve relative links and image
194- references. Relative references remain relative when omitted.
195-
196- extension: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv,
197- md, py, rtf, jpg, png, or txt.
198-
199- filename: Optional filename hint used to infer the extension when extension is omitted.
329+ extension: Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g.
330+ ".pdf").
200331
201332 include_images: Include image references in Markdown output
202333
203334 include_links: Preserve hyperlinks in Markdown output
204335
205- ocr: When true for PDF inputs, detect and OCR images embedded in the selected pages,
206- inserting recognized text at each image's position in page reading order while
207- preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range.
208- This is separate from automatic scanned-PDF OCR fallback.
209-
210- pdf_end: Last 1-based PDF page to parse. When omitted, parsing ends at the last page.
211- Must be greater than or equal to pdfStart when both are provided .
336+ ocr: Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted
337+ at each image's position in page reading order, preserving the text layer;
338+ pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get
339+ full-document OCR, and raster images get their visible text transcribed. When
340+ false, no OCR runs: scanned PDFs may yield no content and images return only
341+ format/dimension metadata. Calls where OCR actually runs cost 5 credits instead
342+ of 1 .
212343
213- pdf_start: First 1-based PDF page to parse. When omitted, parsing starts at the first page.
344+ pdf: PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true)
345+ to an inclusive 1-based page range.
214346
215347 shorten_base64_images: Shorten base64-encoded image data in the Markdown output
216348
@@ -235,14 +367,11 @@ async def handle(
235367 timeout = timeout ,
236368 query = await async_maybe_transform (
237369 {
238- "base_url" : base_url ,
239370 "extension" : extension ,
240- "filename" : filename ,
241371 "include_images" : include_images ,
242372 "include_links" : include_links ,
243373 "ocr" : ocr ,
244- "pdf_end" : pdf_end ,
245- "pdf_start" : pdf_start ,
374+ "pdf" : pdf ,
246375 "shorten_base64_images" : shorten_base64_images ,
247376 "use_main_content_only" : use_main_content_only ,
248377 },
0 commit comments