Get started

Quickstart

Upload a document, extract fields with a template and read the values with their sources.

This takes about five minutes and costs nothing: it uses a test key, which returns sample values in the real response shape.

1. Create a test key#

Sign in, open API keys, choose Create key and pick Test. Copy the key once and keep it in environment variables; never paste it into code, chats or logs.

shell
export PARSEFOX_BASE_URL="https://parsefox.dev"
export PARSEFOX_API_KEY="pf_test_..."   # paste from the console

2. Upload, extract, read#

The examples use the built-in invoice template. Replace invoice.pdf with any PDF, Word, Excel or image file.

curl#

shell
DOC=$(curl -s "$PARSEFOX_BASE_URL/v1/documents" \
  -H "Authorization: Bearer $PARSEFOX_API_KEY" \
  -F file=@invoice.pdf | jq -r .document_id)

JOB=$(curl -s "$PARSEFOX_BASE_URL/v1/extractions?wait=60" \
  -H "Authorization: Bearer $PARSEFOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"document_id\": \"$DOC\", \"template_id\": \"invoice\"}" | jq -r .job_id)

curl -s "$PARSEFOX_BASE_URL/v1/extractions/$JOB/result" \
  -H "Authorization: Bearer $PARSEFOX_API_KEY" | jq '{status, data, unresolved_fields}'

If the job is still pending or running when wait runs out, poll GET /v1/extractions/$JOB?wait=30 until it finishes.

Python#

Uses httpx (pip install httpx).

python
import os
import time

import httpx

api = httpx.Client(
    base_url=os.environ["PARSEFOX_BASE_URL"] + "/v1",
    headers={"Authorization": f"Bearer {os.environ['PARSEFOX_API_KEY']}"},
    timeout=90,
)

with open("invoice.pdf", "rb") as file:
    document = api.post("/documents", files={"file": file}).raise_for_status().json()

job = (
    api.post(
        "/extractions",
        params={"wait": 60},
        json={"document_id": document["document_id"], "template_id": "invoice"},
    )
    .raise_for_status()
    .json()
)
while job["status"] in ("pending", "running"):
    time.sleep(2)
    job = api.get(f"/extractions/{job['job_id']}", params={"wait": 30}).json()

result = api.get(f"/extractions/{job['job_id']}/result").raise_for_status().json()
print(result["data"])
if result["review_required"]:
    print("Needs review:", result["unresolved_fields"])

TypeScript#

Node 20 or newer, no dependencies.

typescript
import { readFile } from "node:fs/promises";

const api = `${process.env.PARSEFOX_BASE_URL}/v1`;
const headers = { Authorization: `Bearer ${process.env.PARSEFOX_API_KEY}` };

async function call(path: string, init: RequestInit = {}) {
  const response = await fetch(`${api}${path}`, { ...init, headers: { ...headers, ...init.headers } });
  const body = await response.json();
  if (!response.ok) throw new Error(`${body.code}: ${body.message}`);
  return body;
}

const form = new FormData();
form.append("file", new Blob([await readFile("invoice.pdf")]), "invoice.pdf");
const document = await call("/documents", { method: "POST", body: form });

let job = await call("/extractions?wait=60", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ document_id: document.document_id, template_id: "invoice" }),
});
while (job.status === "pending" || job.status === "running") {
  job = await call(`/extractions/${job.job_id}?wait=30`);
}

const result = await call(`/extractions/${job.job_id}/result`);
console.log(result.data);
if (result.review_required) console.log("Needs review:", result.unresolved_fields);

3. Look at the result#

json
{
  "object": "extraction_result",
  "status": "completed",
  "review_required": false,
  "data": { "invoice_number": "INV-1042", "total": 1280.5, "items": [] },
  "fields": {
    "/total": {
      "status": "verified",
      "value": 1280.5,
      "raw_value": "$1,280.50",
      "sources": [
        { "unit_id": "page_000001", "locator": { "page_number": 1 }, "quote": "Total due $1,280.50" }
      ]
    }
  },
  "unresolved_fields": []
}
  • data follows the schema exactly.
  • fields is keyed by JSON Pointer (/items/0/amount) and says where each value came from and whether it was verified. See Concepts.
  • With a test key the values are samples such as "Sample invoice number".

Next steps#