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:

PipelineDescriptionBest for
fast (default)Fast text extractionText-heavy PDFs, DOCX, emails, spreadsheets
ocrOCR-based extraction with layout analysisScanned documents, image-heavy PDFs
vlmVision Language Model processingComplex 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

FieldTypeRequiredDescription
filesfile(s)YesOne or more files to convert
pipelinestringNoProcessing pipeline: fast (default), ocr, or vlm. A form field or a query parameter (?pipeline=ocr, the form the API reference lists); both work
optionsJSON partNoPipeline 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

ScenarioPipelineWhy
Text-based PDFs, Word docs, spreadsheetsfastFast, reliable text extraction
Scanned documents, image-heavy PDFsocrLayout analysis with OCR for accurate text recovery
Complex layouts (multi-column, forms, mixed tables)vlmUnderstands spatial layout visually
Plain images with text (PNG, JPG)vlmReads 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:

FieldTypeDefaultDescription
pipelinestring"fast"Processing pipeline: fast, ocr, or vlm
timeoutnumber120Timeout per document in seconds
abortOnErrorbooleanfalseStop batch on first error
extractMetadatabooleantrueInclude document metadata in response
optionsobject—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.

FieldTypeApplies toDescription
outputFormatsarrayall pipelinesWhich outputs to return: MD, TEXT, JSON, HTML. Default: ["MD", "TEXT"]
imageExportModestringocr, vlm; on fast, email attachments that need OCRplaceholder (default) or embedded
ocrLanguagesarrayocr, vlmOCR languages, for example ["en", "de"]
tableStructurebooleanocr, vlmDetect table structure
maxPagesnumberocr, vlmMaximum number of pages to process
imagesScalenumberocr, vlmScale factor for exported images
pictureClassificationbooleanocr, vlmClassify 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, partial_success, or failure, and once the task has finished it matches the result's own status: partial_success means some documents or attachments could not be converted and are listed in the result's errors. taskMeta counts the files you sent: numDocs all of them, numProcessed those finished so far, and of these numSucceeded those that produced at least one document and numFailed those that produced none. A task that fails before it reaches a file, or stops early because of abortOnError, leaves the remaining files out of all three counts. An email whose attachments become separate documents still counts as one file.

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, partial_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

FormatMIME Typefastocrvlm
PDFapplication/pdfyesyesyes
DOCXapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentyesyesyes
XLSXapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetyesyesyes
PPTXapplication/vnd.openxmlformats-officedocument.presentationml.presentationyesyesyes
HTMLtext/htmlyesyesyes
Markdowntext/markdownyesyesyes
CSVtext/csvyesyesyes
TXTtext/plainyes——
MSG (Outlook)application/vnd.ms-outlookyes——
EMLmessage/rfc822yes——
ZIPapplication/zipyes——
Imagesimage/*—yesyes
AsciiDoctext/asciidoc—yesyes
DXF (AutoCAD)image/vnd.dxfyes——
DWG (AutoCAD)image/vnd.dwgyes——
STEPmodel/stepyes——
GEO (TRUMPF)application/vnd.trumpf.geoyes——

CAD files come back as structured JSON; in Markdown and text output it sits in a code block. A DXF or DWG drawing gives its version, units, bounding box, layers and entities. A STEP model (.step or .stp) gives its header, products and assembly structure, properties, and geometry such as bounding box, volume and surface area. A GEO file gives material, thickness, contours, bends and dimensions.

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

FormatKey in ResponseDescription
MDmdContentMarkdown with headings and structure preserved
TEXTtextContentPlain text, no formatting
JSONjsonContentStructured JSON representation
HTMLhtmlContentHTML markup

Status Codes

StatusHTTP CodeMeaning
SUCCESS200All documents converted
PARTIAL_SUCCESS207Some documents failed
FAILURE422All documents failed
PENDING202Async task queued
PROCESSING202Async task in progress

Was this page helpful?

A request failed? See Errors for every status and code.