Document Conversion
Turn PDFs, Word docs, emails, and ZIP archives into clean text —ready for extraction or any downstream processing.
How It Works
Send a document via URL, base64, or file upload and get back its content as Markdown, plain text, JSON, or HTML. 2kw.ai handles format detection, parsing, and text extraction automatically. All you need is an API key.
17 input formats supported
PDF, DOCX, XLSX, PPTX, CSV, TXT, HTML, Markdown, AsciiDoc, MSG (Outlook), EML, ZIP, Images (any image/* type), DXF (AutoCAD), DWG (AutoCAD), STEP, and GEO (TRUMPF). Output as Markdown, Plain Text, JSON, or HTML.
Pipelines
2kw.ai offers three processing pipelines. Choose the one that fits your document type:
| Pipeline | Description | Best for |
|---|---|---|
fast (default) | Fast text extraction | Text-heavy PDFs, DOCX, emails, spreadsheets |
ocr | OCR-based extraction with layout analysis | Scanned documents, image-heavy PDFs |
vlm | Vision Language Model processing | Complex layouts, mixed text+images, plain images |
The fast pipeline is the default and works for most documents. Use ocr or vlm when you need to process scanned or image-heavy content. Not every format supports every pipeline — see the supported formats table for the full matrix.
Convert from URL
POST /v1/convert/source
The primary endpoint. Pass one or more document URLs and get back converted text.
Request
curl -X POST https://api.2kw.ai/v1/convert/source \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk_your_api_key" \
-d '{
"sources": [
{
"kind": "http",
"url": "https://example.com/document.pdf"
}
]
}'
Response
{
"documents": [
{
"filename": "document.pdf",
"mdContent": "# Document Title\n\nExtracted content..."
}
],
"status": "SUCCESS",
"errors": [],
"processingTime": 1.234
}
Source Types
Each source in the sources array needs a kind field:
HTTP source —fetch a document from a URL:
{
"kind": "http",
"url": "https://example.com/document.pdf",
"headers": {
"Authorization": "Bearer external-token"
}
}
The optional headers field lets you pass authentication or custom headers to the source server.
Base64 source —send the document content directly:
{
"kind": "base64",
"content": "JVBERi0xLjQK...",
"filename": "document.pdf",
"mimeType": "application/pdf"
}
Batch Conversion
Convert multiple documents in a single request:
{
"sources": [
{ "kind": "http", "url": "https://example.com/report.pdf" },
{ "kind": "http", "url": "https://example.com/notes.docx" }
],
"options": {
"abortOnError": false
}
}
When abortOnError is false (the default), the API processes all documents even if some fail. Failed documents appear in the errors array, and the status will be PARTIAL_SUCCESS (HTTP 207).
Convert Uploaded Files
POST /v1/convert/file
Upload files directly using multipart/form-data:
Request
curl -X POST https://api.2kw.ai/v1/convert/file \
-H "Authorization: Bearer sk_your_api_key" \
-F "files=@document.pdf" \
-F "files=@notes.docx"
File Upload Parameters
| Field | Type | Required | Description |
|---|---|---|---|
files | file(s) | Yes | One or more files to convert |
pipeline | string | No | Processing pipeline: fast (default), ocr, or vlm. A form field or a query parameter (?pipeline=ocr, the form the API reference lists); both work |
options | JSON part | No | Pipeline options as a JSON object. Send it as a part with Content-Type: application/json, e.g. -F 'options={"ocrLanguages":["de"]};type=application/json' |
OCR and VLM Pipelines
For scanned documents, image-heavy PDFs, or complex layouts where the default fast pipeline falls short, use the ocr or vlm pipeline.
Pipeline examples
curl -X POST https://api.2kw.ai/v1/convert/source \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk_your_api_key" \
-d '{
"sources": [
{
"kind": "http",
"url": "https://example.com/scanned-document.pdf"
}
],
"options": {
"pipeline": "ocr",
"options": {
"ocrLanguages": ["en", "de"],
"tableStructure": true
}
}
}'
When to Use Each Pipeline
| Scenario | Pipeline | Why |
|---|---|---|
| Text-based PDFs, Word docs, spreadsheets | fast | Fast, reliable text extraction |
| Scanned documents, image-heavy PDFs | ocr | Layout analysis with OCR for accurate text recovery |
| Complex layouts (multi-column, forms, mixed tables) | vlm | Understands spatial layout visually |
| Plain images with text (PNG, JPG) | vlm | Reads the image as a vision model would |
Pipeline speed vs accuracy
The fast pipeline is the fastest and best for most text-heavy documents. The ocr and vlm pipelines are slower but produce better results for documents where layout matters or text is embedded in images.
Conversion Options
When using the /source endpoint, you can pass an options object:
Top-level options:
| Field | Type | Default | Description |
|---|---|---|---|
pipeline | string | "fast" | Processing pipeline: fast, ocr, or vlm |
timeout | number | 120 | Timeout per document in seconds |
abortOnError | boolean | false | Stop batch on first error |
extractMetadata | boolean | true | Include document metadata in response |
options | object | — | Pipeline options, see below |
Pipeline Options
The nested options.options object tunes the output and the ocr/vlm pipelines. On /file endpoints, send the same object as the options part. Every field is optional; leave one out to use the pipeline's default.
| Field | Type | Applies to | Description |
|---|---|---|---|
outputFormats | array | all pipelines | Which outputs to return: MD, TEXT, JSON, HTML. Default: ["MD", "TEXT"] |
imageExportMode | string | ocr, vlm; on fast, email attachments that need OCR | placeholder (default) or embedded |
ocrEngine | string | ocr, vlm | OCR engine, for example easyocr or tesseract |
ocrLanguages | array | ocr, vlm | OCR languages, for example ["en", "de"] |
pdfBackend | string | ocr, vlm | PDF backend, for example dlparser or pypdfium2 |
tableStructure | boolean | ocr, vlm | Detect table structure |
maxPages | number | ocr, vlm | Maximum number of pages to process |
imagesScale | number | ocr, vlm | Scale factor for exported images |
pictureClassification | boolean | ocr, vlm | Classify pictures in the document |
For example, to get only Markdown and HTML back:
{
"sources": [{ "kind": "http", "url": "https://example.com/report.pdf" }],
"options": {
"options": { "outputFormats": ["MD", "HTML"] }
}
}
Async Conversion
For large documents or batch jobs, use the async endpoints to avoid timeouts.
Start an Async Job
POST /v1/convert/source/async
Same request body as the sync endpoint. Returns 202 Accepted immediately with a task ID, a Location header pointing at the task (/v1/convert/tasks/{taskId}), and Retry-After: 5:
{
"taskId": "task-uuid",
"taskType": "CONVERT",
"taskStatus": "pending",
"taskMeta": {
"numDocs": 2,
"numProcessed": 0,
"numSucceeded": 0,
"numFailed": 0
}
}
taskStatus is one of pending, processing, success, or failure. failure means the task itself failed; a task that finished is success even when some of its documents could not be converted, so read the result's own status and errors to tell a full from a partial success. taskMeta.numDocs counts the files you sent; once the task has finished, numSucceeded counts the documents returned (an email's attachments count separately) and numFailed the errors.
Poll Task Status
GET /v1/convert/tasks/{taskId}
Check whether the task is still running:
curl https://api.2kw.ai/v1/convert/tasks/{taskId} \
-H "Authorization: Bearer sk_your_api_key"
The response has the same shape as above. Add ?wait=30 for long polling (at most 60 seconds).
Get the Result
GET /v1/convert/tasks/{taskId}/result
Once taskStatus is success or failure, fetch the full result. It has the same shape as a synchronous response:
curl https://api.2kw.ai/v1/convert/tasks/{taskId}/result \
-H "Authorization: Bearer sk_your_api_key"
File uploads can be async too
Use /v1/convert/file/async with the same multipart format. You'll get back a task ID to poll.
Supported Formats
Input
| Format | MIME Type | fast | ocr | vlm |
|---|---|---|---|---|
application/pdf | yes | yes | yes | |
| DOCX | application/vnd.openxmlformats-officedocument.wordprocessingml.document | yes | yes | yes |
| XLSX | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | yes | yes | yes |
| PPTX | application/vnd.openxmlformats-officedocument.presentationml.presentation | yes | yes | yes |
| HTML | text/html | yes | yes | yes |
| Markdown | text/markdown | yes | yes | yes |
| CSV | text/csv | yes | yes | yes |
| TXT | text/plain | yes | — | — |
| MSG (Outlook) | application/vnd.ms-outlook | yes | — | — |
| EML | message/rfc822 | yes | — | — |
| ZIP | application/zip | yes | — | — |
| Images | image/* | — | yes | yes |
| AsciiDoc | text/asciidoc | — | yes | yes |
| DXF (AutoCAD) | image/vnd.dxf | yes | — | — |
| GEO (TRUMPF) | application/vnd.trumpf.geo | yes | — | — |
Container formats
ZIP archives and email files (MSG, EML) are automatically expanded — each contained file is processed individually through the appropriate pipeline. Nested containers (e.g., a ZIP containing emails with attachments, or ZIPs within ZIPs) are handled recursively.
Output
| Format | Key in Response | Description |
|---|---|---|
MD | mdContent | Markdown with headings and structure preserved |
TEXT | textContent | Plain text, no formatting |
JSON | jsonContent | Structured JSON representation |
HTML | htmlContent | HTML markup |
Status Codes
| Status | HTTP Code | Meaning |
|---|---|---|
SUCCESS | 200 | All documents converted |
PARTIAL_SUCCESS | 207 | Some documents failed |
FAILURE | 422 | All documents failed |
PENDING | 202 | Async task queued |
PROCESSING | 202 | Async task in progress |