Skip to content

Docling: Document Conversion API ​

Docling converts documents into structured formats that can be used for search, retrieval-augmented generation (RAG), archiving, and content processing. It can preserve document structure such as headings, tables, and reading order, and it supports OCR for scanned documents.

Supported Formats ​

The following file formats can be uploaded:

  • PDF
  • DOCX, PPTX, and XLSX
  • PNG, JPEG, TIFF, BMP, and GIF
  • HTML, AsciiDoc, Markdown, and CSV

Conversion output is available as Markdown, JSON, YAML, HTML, plain text, or DocTags.

Limitations

The maximum request size depends on the upload method:

  • Direct file upload (/v1/convert/file, /v1/convert/file/async): 10 MB per request, limited by the Digital Marketplace gateway.
  • URL source (/v1/convert/source, /v1/convert/source/async): 100 MB per request, using a publicly accessible or presigned URL on the dedicated endpoint.

Credentials embedded in URLs and request headers must be handled as secrets.

Get Started ​

The production URL is available in the Documentation section of the corresponding plan in the Digital Marketplace. Set BASE_URL to this URL and DOCLING_API_KEY to the access token from the subscription credentials.

For instructions on activating credentials and creating an API key, see the Inference Endpoints quickstart.

Conversion Workflows ​

Docling provides synchronous and asynchronous conversion. Synchronous conversion is suitable when the result can be returned within the request timeout. Asynchronous conversion is recommended for large or complex documents.

WorkflowSubmit endpointResult
File, synchronousPOST /v1/convert/fileConversion result
URL, synchronousPOST /v1/convert/sourceConversion result
File, asynchronousPOST /v1/convert/file/asyncTask status with task_id
URL, asynchronousPOST /v1/convert/source/asyncTask status with task_id
Poll asynchronous taskGET /v1/status/poll/{task_id}Current task status
Fetch asynchronous resultGET /v1/result/{task_id}Conversion result

The /v1/models endpoint lists the models available to the subscribed plan.

Conversion Options ​

OptionTypeDefaultDescription
to_formatsarray["md"]Output formats. Supported values: md, json, yaml, html, text, and doctags
from_formatsarrayAuto-detectRestricts accepted input formats
image_export_modestringembedded for URL sourcesImage handling mode: placeholder, embedded, or referenced
do_ocrbooleantrueEnables OCR in the standard pipeline for scanned documents
pipelinestringstandardProcessing pipeline. Set to vlm to use dots.ocr
page_rangearrayAll pagesTwo integers specifying the first and last page, inclusive and starting at page 1

Use dots.ocr ​

Set pipeline to vlm to process a document with dots.ocr. This vision-language model is suitable for documents with complex layouts, tables, charts, formulas, or text embedded in images.

INFO

The Swiss AI Platform configures the dots.ocr model and its processing parameters. Only pipeline=vlm is required; no model URL or VLM configuration needs to be supplied.

For a file upload:

bash
curl -X POST "$BASE_URL/v1/convert/file" \
  -H "Authorization: Bearer $DOCLING_API_KEY" \
  -F "files=@document.pdf" \
  -F "to_formats=md" \
  -F "pipeline=vlm"

For a URL source:

bash
curl -X POST "$BASE_URL/v1/convert/source" \
  -H "Authorization: Bearer $DOCLING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sources": [{"kind": "http", "url": "https://example.com/document.pdf"}],
    "options": {
      "to_formats": ["md"],
      "pipeline": "vlm"
    }
  }'

Synchronous Conversion ​

Convert an Uploaded File ​

bash
curl -X POST "$BASE_URL/v1/convert/file" \
  -H "Authorization: Bearer $DOCLING_API_KEY" \
  -F "files=@document.pdf" \
  -F "to_formats=md" \
  -F "do_ocr=true" \
  -F "pipeline=standard"

Multiple files can be included by repeating the files field.

Convert a URL Source ​

bash
curl -X POST "$BASE_URL/v1/convert/source" \
  -H "Authorization: Bearer $DOCLING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sources": [
      {
        "kind": "http",
        "url": "https://example.com/document.pdf",
        "headers": {}
      }
    ],
    "options": {
      "to_formats": ["md"],
      "do_ocr": true,
      "pipeline": "standard"
    }
  }'

Each entry in sources requires a kind field, which selects the source type. Valid values:

  • http: fetches the document from a URL. Requires url. Additional HTTP headers for fetching a protected source can be supplied in the optional headers object. A presigned URL can be used without additional headers.
  • file: submits the document inline. Requires base64_string with the base64-encoded file content (for example, from base64 -w 0 document.pdf) and filename.

Python Example ​

python
import os

import requests

base_url = os.environ["BASE_URL"]
headers = {"Authorization": f"Bearer {os.environ['DOCLING_API_KEY']}"}

with open("document.pdf", "rb") as document:
    response = requests.post(
        f"{base_url}/v1/convert/file",
        headers=headers,
        files={"files": ("document.pdf", document, "application/pdf")},
        data={"to_formats": "md", "do_ocr": "true", "pipeline": "standard"},
        timeout=120,
    )

response.raise_for_status()
print(response.json()["document"]["md_content"])

Asynchronous Conversion ​

An asynchronous request returns a task_id. The task status must be polled until it reaches success, failure, or partial_success. The result can then be fetched for a successful task.

bash
# Submit the document.
TASK_ID=$(
  curl -sS -X POST "$BASE_URL/v1/convert/file/async" \
    -H "Authorization: Bearer $DOCLING_API_KEY" \
    -F "files=@document.pdf" \
    -F "to_formats=md" \
  | jq -r '.task_id'
)

# Poll the task. The optional wait value enables long-polling.
curl -X GET "$BASE_URL/v1/status/poll/$TASK_ID?wait=30" \
  -H "Authorization: Bearer $DOCLING_API_KEY"

# Fetch the result after task_status is success.
curl -X GET "$BASE_URL/v1/result/$TASK_ID" \
  -H "Authorization: Bearer $DOCLING_API_KEY"

Billing

For synchronous file conversion, pages are counted from the uploaded file. For synchronous URL conversion, pages are taken from the conversion response when available.

For asynchronous conversion, usage is recorded when /v1/result/{task_id} is called. Polling the status does not record usage.

Response ​

A successful conversion returns the exported document, its status, any conversion errors, and processing timing information.

json
{
  "document": {
    "filename": "document.pdf",
    "md_content": "# Converted document\n\n...",
    "json_content": null,
    "html_content": null,
    "text_content": null,
    "doctags_content": null
  },
  "status": "success",
  "errors": [],
  "processing_time": 4.21,
  "timings": {}
}

The requested content is returned in the document object. Content fields that were not generated are null.

Asynchronous tasks can have the following statuses: pending, started, success, partial_success, failure, or skipped.

Errors ​

HTTP statusMeaning
400The request is malformed or required request attributes are missing
401The access token is missing, expired, or invalid
403The subscribed plan is not authorized to use Docling
404The asynchronous task does not exist or has expired
413The uploaded request exceeds the size limit (10 MB for file uploads, 100 MB for URL sources)
422Docling could not process the document
502The Docling backend is unavailable

Error responses include a machine-readable code and message. The optional event_id can be included when contacting support.