Appearance
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:
- 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.
| Workflow | Submit endpoint | Result |
|---|---|---|
| File, synchronous | POST /v1/convert/file | Conversion result |
| URL, synchronous | POST /v1/convert/source | Conversion result |
| File, asynchronous | POST /v1/convert/file/async | Task status with task_id |
| URL, asynchronous | POST /v1/convert/source/async | Task status with task_id |
| Poll asynchronous task | GET /v1/status/poll/{task_id} | Current task status |
| Fetch asynchronous result | GET /v1/result/{task_id} | Conversion result |
The /v1/models endpoint lists the models available to the subscribed plan.
Conversion Options ​
| Option | Type | Default | Description |
|---|---|---|---|
to_formats | array | ["md"] | Output formats. Supported values: md, json, yaml, html, text, and doctags |
from_formats | array | Auto-detect | Restricts accepted input formats |
image_export_mode | string | embedded for URL sources | Image handling mode: placeholder, embedded, or referenced |
do_ocr | boolean | true | Enables OCR in the standard pipeline for scanned documents |
pipeline | string | standard | Processing pipeline. Set to vlm to use dots.ocr |
page_range | array | All pages | Two 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. Requiresurl. Additional HTTP headers for fetching a protected source can be supplied in the optionalheadersobject. A presigned URL can be used without additional headers.file: submits the document inline. Requiresbase64_stringwith the base64-encoded file content (for example, frombase64 -w 0 document.pdf) andfilename.
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 status | Meaning |
|---|---|
400 | The request is malformed or required request attributes are missing |
401 | The access token is missing, expired, or invalid |
403 | The subscribed plan is not authorized to use Docling |
404 | The asynchronous task does not exist or has expired |
413 | The uploaded request exceeds the size limit (10 MB for file uploads, 100 MB for URL sources) |
422 | Docling could not process the document |
502 | The Docling backend is unavailable |
Error responses include a machine-readable code and message. The optional event_id can be included when contacting support.
