Skip to main content

API Quick Start

Process your first document in three steps: submit, poll, read results.

What You Need

  1. An API key: manage keys through the web UI at Settings → Integrations (/integration)
  2. Your tenant ID and project ID (find them in the UI under your user icon and Library → Project Properties)
  3. A configured project with at least one document class and extraction fields

Step 1: Submit a Document

curl -X POST "https://app.docaifabric.com/tenants/{tenant_id}/projects/{project_id}/transactions/process" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"source_files": [
{
"filename": "invoice.pdf",
"base64_data": "'$(base64 -i invoice.pdf)'"
}
]
}'

You'll get back a transaction_id:

{
"transaction_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "processing",
"poll_url": "/transactions/550e8400-e29b-41d4-a716-446655440000?timeout=30"
}

Step 2: Poll for Completion

Wait for results using long-polling (the server holds the connection up to 30 seconds):

curl "https://app.docaifabric.com/transactions/{transaction_id}?timeout=30" \
-H "X-API-Key: your-api-key"

Repeat until status is completed (or failed).

Step 3: Retrieve the Results

The status endpoint tells you when a transaction is done; the extracted data is retrieved from the export files. List the export manifest:

curl "https://app.docaifabric.com/transactions/{transaction_id}/exports" \
-H "X-API-Key: your-api-key"

Then download the default JSON results file ({transaction_id}_data.json):

curl "https://app.docaifabric.com/transactions/{transaction_id}/exports/download/{transaction_id}_data.json" \
-H "X-API-Key: your-api-key" -OJ

The JSON contains a documents array; each document's fields are keyed by field ID, and every field has a value, confidence score, and display name:

{
"documents": [
{
"document_type": "Invoice",
"classification_confidence": 0.98,
"fields": {
"717dd8c1": { "name": "Invoice Number", "value": "INV-12345", "confidence": 0.95 },
"86ff6bd8": { "name": "Total Amount", "value": "1,250.00", "confidence": 0.92 }
}
}
]
}

See Process Documents via API for the full schema.

Full Python Example

import requests, base64

BASE_URL = "https://app.docaifabric.com"
HEADERS = {"X-API-Key": "your-api-key"}
TENANT = "your-tenant-id"
PROJECT = "your-project-id"

# Submit
with open("invoice.pdf", "rb") as f:
file_data = base64.b64encode(f.read()).decode()

tx = requests.post(
f"{BASE_URL}/tenants/{TENANT}/projects/{PROJECT}/transactions/process",
headers={**HEADERS, "Content-Type": "application/json"},
json={"source_files": [{"filename": "invoice.pdf", "base64_data": file_data}]}
).json()

# Poll for completion
while True:
result = requests.get(
f"{BASE_URL}/transactions/{tx['transaction_id']}?timeout=30",
headers=HEADERS
).json()
if result["status"] in ("completed", "failed"):
break

# Retrieve results from the JSON export
manifest = requests.get(
f"{BASE_URL}/transactions/{tx['transaction_id']}/exports",
headers=HEADERS
).json()
json_file = next(
f["filename"]
for p in manifest["profiles"].values() if p["output_format"] == "json"
for f in p["files"]
)
data = requests.get(
f"{BASE_URL}/transactions/{tx['transaction_id']}/exports/download/{json_file}",
headers=HEADERS
).json()

for doc in data["documents"]:
print(f"Type: {doc['document_type']}")
for fid, f in doc["fields"].items():
print(f" {f['name']}: {f['value']}")

Next Steps

  • Process Documents via API: Multi-step uploads, batch status checks, field filtering, datasets, and more
  • Webhooks: Skip polling and have results pushed to your endpoint
  • Datasets: Route documents to Playground, Production, or Evaluation datasets
  • Authentication: API key management and permissions