Quickstart
Before you start
You need an API key. DocSlice is in private beta and accounts are created by invitation (Get access explains how). Export the key in your terminal so the examples can read it:
export DOCSLICE_API_KEY="your key here"
Send a document
POST
/v1/convertRequires an API keyThe request is a multipart/form-data upload: the document goes in the file field and format chooses the output (json, markdown or html).
curl -s https://api.docslice.app/v1/convert \
-H "Authorization: Bearer $DOCSLICE_API_KEY" \
-F "file=@invoice.pdf" \
-F "format=json"
import json
import os
import requests
api_key = os.environ["DOCSLICE_API_KEY"]
with open("invoice.pdf", "rb") as handle:
response = requests.post(
"https://api.docslice.app/v1/convert",
headers={"Authorization": f"Bearer {api_key}"},
files={"file": ("invoice.pdf", handle, "application/pdf")},
data={"format": "json"},
timeout=120,
)
print(json.dumps(response.json(), indent=2))
const fs = require("node:fs");
const form = new FormData();
form.append("file", new Blob([fs.readFileSync("invoice.pdf")], { type: "application/pdf" }), "invoice.pdf");
form.append("format", "json");
fetch("https://api.docslice.app/v1/convert", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.DOCSLICE_API_KEY}` },
body: form,
})
.then((response) => response.json())
.then((data) => console.log(JSON.stringify(data, null, 2)));
<?php
$curl = curl_init('https://api.docslice.app/v1/convert');
curl_setopt_array($curl, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('DOCSLICE_API_KEY')],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('invoice.pdf', 'application/pdf', 'invoice.pdf'),
'format' => 'json',
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
]);
echo curl_exec($curl);
curl_close($curl);
The answer contains the text of the document in data, together with the number of pages billed and whether OCR was needed (ocr_applied).
Check that the service is up
curl -s https://api.docslice.app/health
import json
import requests
response = requests.get("https://api.docslice.app/health", timeout=30)
print(json.dumps(response.json(), indent=2))
fetch("https://api.docslice.app/health")
.then((response) => response.json())
.then((data) => console.log(JSON.stringify(data, null, 2)));
<?php
echo file_get_contents('https://api.docslice.app/health');