Developer API

Document operations and downloads

How v2 document operations move through queued, running, completed, failed and cancelled, how to poll them, and how to download the output version.

Operation lifecycle

POST /api/v2/document-operations with documentId, the exact versionId, toolId, parameters and idempotencyKey returns 202 and an operation in state queued. GET /api/v2/document-operations/{operationId} then reports one of the states below; completed, failed and cancelled are final.

Omitting versionId runs the operation on the document's current version at the time of the request. Send it explicitly so a later upload cannot change what you process.

StateFinalMeaningWhat to do
queuedNoAccepted and waiting to start.Poll again after the Retry-After seconds (2).
runningNoProcessing the input version.Poll again after the Retry-After seconds (1).
cancellingNoA stop was requested; processing stops at the next safe point.Keep polling until cancelled, completed or failed.
completedYesThe output is stored as a new immutable version; outputVersionId (and outputDocumentId when it differs) identify it.Download GET /api/v2/documents/{documentId}/versions/{versionId}/content.
failedYesProcessing ended without an output. errorCode and errorMessage explain why.Fix the input or parameters, then create a new operation with a new idempotency key.
cancelledYesProcessing was stopped before an output was produced.Create a new operation if the work is still needed.

Page images

GET /api/v2/documents/{documentId}/versions/{versionId}/pages/{page}/render draws one page of an exact version as an image: width (16 to 4096 pixels) or dpi (36 to 300, default 96), and format png (default) or webp (lossless). A width wins over a dpi.

Renders are cached: the same version, page, size and format is drawn once, and the render does not appear in your documents list. For a new render the route waits a few seconds and returns the image (200, Cache-Control private and immutable, the render operation's ID in X-Wellfriend-Operation-Id). If the image is not ready yet it returns 202 with the operation and Retry-After; ask again after that delay.

Each request costs one request unit, like a version download. A page the document does not have returns 404 PAGE_NOT_FOUND. The SDKs wait for you: renderPage (TypeScript), render_page (Python and Rust), RenderPage (Go); in MCP, document_page_render returns a single-use download link.

Supported tools

POST /api/v2/document-operations runs the 49 website tools plus Edit PDF and Render page on an exact document version. Same-format PDF tools publish their result as the document's next immutable version (outputKind version); conversions, exports, splits and image tools publish it as a new derived document whose first version is linked to the input version (outputKind artifact). Either way the completed operation reports outputDocumentId and outputVersionId: download them with GET /api/v2/documents/{documentId}/versions/{versionId}/content, or document_download_link in MCP.

parameters takes the tool's options from the Tool reference (/docs/developer-api/tools; tools_catalog in MCP). Every value is checked before the operation is accepted: unknown options, values outside their choices or range, a missing option the selected mode requires, and AI mode return 400 OPERATION_INPUT_INVALID with the reason; an input version the tool cannot read returns 422 OPERATION_INPUT_UNSUPPORTED. Passwords and passphrases are stored encrypted and read back as [redacted].

inputs lists further input versions after documentId, in processing order: merge-pdf takes 2 to 30 PDFs in all, image-to-pdf 1 to 50 images. assets names further files: watermarkImage (add-watermark type image, watermark-image mode image), signatureImage and stampImage (sign-pdf) as {documentId, versionId}, and the sign-pdf certificateFile inline as {content: base64, fileName}, which is stored encrypted and never kept as a document. Each one must be a version in the same workspace, of a type and size the tool accepts; the completed operation reports inputs and assets.

Every operation is metered like any other and is idempotent on its idempotencyKey. A toolId that is not in the table below returns 422 OPERATION_UNSUPPORTED.

toolIdToolOutputAcceptsNotes
add-page-numbersAdd Page NumbersNext version of the same documentapplication/pdf—
add-watermarkAdd WatermarkNext version of the same documentapplication/pdfasset watermarkImage required when type is image
check-pdfCheck PDFNew derived documentapplication/pdf, .pdf—
compress-pdfCompressNext version of the same documentapplication/pdf, image/jpeg, image/png, image/webp, image/gif, image/tiff, image/bmp, image/avif, .pdf, .jpg, .jpeg, .png, .webp, .gif, .tif, .tiff, .bmp, .avif—
convert-from-jpgConvert from JPGNew derived documentimage/jpeg—
convert-to-jpgConvert to JPGNew derived documentimage/png, image/webp, image/avif, image/tiff, image/jpeg—
crop-imageCrop ImageNew derived documentimage/jpeg, image/png, image/webp, image/avif, image/tiff—
crop-pdfCrop PDFNext version of the same documentapplication/pdf, .pdf—
csv-to-pdfCSV to PDFNew derived documenttext/csv, text/plain, .csv—
edit-metadataCheck & Edit MetadataNext version of the same documentapplication/pdfAI-mode values are not accepted through the API: engine "ai", preset "ai-suggest"; batch true is not accepted (run edit-metadata on each document)
excel-to-pdfExcel to PDFNew derived documentapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.oasis.opendocument.spreadsheet, .xlsx, .ods—
flatten-pdfFlatten PDFNext version of the same documentapplication/pdf—
image-metadataImage MetadataNew derived documentimage/png, image/jpeg, image/webp, image/gif—
image-to-pdfImage to PDFNew derived documentimage/png, image/jpeg, image/webp, .png, .jpg, .jpeg, .webp1 to 50 input versions (documentId plus inputs); AI-mode values are not accepted through the API: engine "ai", altText true
json-to-pdfJSON to PDFNew derived documentapplication/json, text/plain, .json—
markdown-to-pdfMarkdown to PDFNew derived documenttext/markdown, text/plain, .md, .markdown—
merge-pdfMerge PDFNew derived documentapplication/pdf2 to 30 input versions (documentId plus inputs)
n-up-pdfN-up PDFNext version of the same documentapplication/pdf, .pdf—
ocr-pdfOCR PDFNew derived documentapplication/pdf, image/png, image/jpeg, image/tiff, image/webp, image/gif, image/bmp, image/avif, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/csv, text/tab-separated-values, message/rfc822, application/vnd.ms-outlook, application/zip, .pdf, .png, .jpg, .jpeg, .tif, .tiff, .webp, .gif, .bmp, .avif, .docx, .pptx, .xlsx, .csv, .tsv, .eml, .msg, .zippassword is kept encrypted and never returned
organize-pdfOrganize PDFNext version of the same documentapplication/pdf—
pdf-editEdit PDFNext version of the same documentapplication/pdf, .pdf—
pdf-table-extractionPDF Table ExtractionNew derived documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", extractionMode "ocr"
pdf-to-chunksPDF to ChunksNew derived documentapplication/pdf, .pdf—
pdf-to-epubPDF to EPUBNew derived documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", extractionMode "ocr"
pdf-to-excelPDF to ExcelNew derived documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", extractionMode "ocr"
pdf-to-htmlPDF to HTMLNew derived documentapplication/pdf, .pdf—
pdf-to-imagesPDF to ImagesNew derived documentapplication/pdf, .pdf—
pdf-to-jsonPDF to JSONNew derived documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", extractionMode "ocr"
pdf-to-markdownPDF to MarkdownNew derived documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", extractionMode "ocr"
pdf-to-powerpointPDF to PowerPointNew derived documentapplication/pdf, .pdf—
pdf-to-textPDF to TextNew derived documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", extractionMode "ocr"
pdf-to-wordPDF to WordNew derived documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", extractionMode "ocr"
pdfa-conversionPDF/A ConversionNext version of the same documentapplication/pdf, .pdfAI-mode values are not accepted through the API: engine "ai", altText true
powerpoint-to-pdfPowerPoint to PDFNew derived documentapplication/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.oasis.opendocument.presentation, .pptx, .odp—
protect-pdfProtect PDFNext version of the same documentapplication/pdfpassword and ownerPassword are kept encrypted and never returned
render-pageRender pageNew derived documentapplication/pdf, .pdf—
repair-pdfRepair PDFNext version of the same documentapplication/pdf—
resize-imageResize ImageNew derived documentimage/jpeg, image/png, image/webp, image/avif, image/tiff—
rotate-imageRotate ImageNew derived documentimage/jpeg, image/png, image/webp, image/avif, image/tiff—
rotate-pdfRotate PDFNext version of the same documentapplication/pdf—
sanitize-pdfSanitize PDFNext version of the same documentapplication/pdf, .pdf—
redact-pdfRedact PDFNext version of the same documentapplication/pdf, .pdf—
scale-pdfScale PDFNext version of the same documentapplication/pdf, .pdf—
sign-pdfSign PDFNext version of the same documentapplication/pdfasset signatureImage required when signatureType is image; asset stampImage; asset certificateFile (inline) required when signatureType is digital; certificatePassphrase is kept encrypted and never returned
split-pdfSplit PDFNew derived documentapplication/pdfAI-mode values are not accepted through the API: engine "ai", mode "ai" or "ocr"
svg-to-pdfSVG to PDFNew derived documentimage/svg+xml, text/xml, application/xml, .svg—
text-to-pdfText to PDFNew derived documenttext/plain, .txt—
unlock-pdfUnlock PDFNext version of the same documentapplication/pdfpassword is kept encrypted and never returned
watermark-imageWatermark ImageNew derived documentimage/jpeg, image/png, image/webp, image/avif, image/tiffasset watermarkImage required when mode is image
web-captureWeb page to PDF or imageNew derived documenttext/html, text/plain, .html, .htm, .txt, .url—
word-to-pdfWord to PDFNew derived documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.oasis.opendocument.text, .docx, .odt—

Create response

The response body is { "operation": {...}, "accepted": true } with HTTP 202. Repeating the call with the same idempotencyKey returns 200 with the original operation and accepted false, so a retry never queues or charges the work twice.

The operation carries id, toolId, state, documentId, inputVersionId, parameters, createdAt and, once known, startedAt, completedAt, outputDocumentId, outputVersionId, outputKind (version or artifact), result, errorCode and errorMessage. inputRepaired is true when the input PDF was damaged and was repaired, at no extra cost, before the tool ran.

For compress-pdf, result.metadata.keptOriginalBecauseNoSmallerOutput is true when no smaller valid PDF exists and the original is returned unchanged. Such an operation is not charged: its request unit is given back when it completes, whether it was a direct call, a chain step or a workflow step.

Polling

Poll GET /api/v2/document-operations/{operationId} while the state is queued, running or cancelling, waiting the Retry-After seconds it returns, give every request a timeout, and set an overall deadline. Stop on failed or cancelled and read errorCode.

For production workflows subscribe a webhook endpoint instead of polling; see /docs/webhooks.

Downloads

When the state is completed, download GET /api/v2/documents/{documentId}/versions/{versionId}/content with the operation's outputVersionId (and outputDocumentId when present). The scope is documents.read and the call is metered. The response streams the exact stored bytes of that immutable version.

GET /api/v2/documents/{documentId}/versions/{versionId} returns the version's metadata (size, SHA-256, MIME type, page count when known) without the bytes.

Retry behavior

If creation failed before acceptance, correct the request and submit again. If the operation was accepted, keep polling it rather than creating duplicates. If it failed, create a new operation with a new idempotency key only after deciding the input or parameters should change.