Invoice Extraction

Extract structured data from invoices and receipts in three steps.

1

Send your document

POST an invoice image or PDF to the API. You can send a file as multipart form data, a base64-encoded string, or just a URL pointing to the document.

curl — upload a file
curl -X POST https://api.contexa.works/api/v1/invoice \
  -H "x-rapidapi-key: YOUR_API_KEY" \
  -F "file=@invoice.pdf"
curl — from a URL
curl -X POST https://api.contexa.works/api/v1/invoice \
  -H "x-rapidapi-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/invoice.png"}'
curl — base64
curl -X POST https://api.contexa.works/api/v1/invoice \
  -H "x-rapidapi-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "base64": "'$(base64 -i invoice.pdf)'",
    "mimeType": "application/pdf"
  }'

You can also pass a prompt field with custom instructions like "Convert all prices to USD" or "Only extract line items".

2

Get structured JSON

The API returns a clean JSON object with all extracted fields:

response
{
  "id": "a1b2c3d4-...",
  "status": "completed",
  "processingTimeMs": 1830,
  "data": {
    "invoiceNumber": "INV-2024-0042",
    "date": "2024-06-15",
    "dueDate": "2024-07-15",
    "vendor": {
      "name": "Acme Design Studio",
      "address": "Torstraße 123, 10119 Berlin",
      "taxId": "DE312345678"
    },
    "customer": {
      "name": "Widget Corp",
      "address": "456 Oxford St, London W1",
      "taxId": null
    },
    "lineItems": [
      {
        "description": "Brand identity design",
        "quantity": 1,
        "unitPrice": 4500,
        "amount": 4500
      },
      {
        "description": "Website mockups (5 pages)",
        "quantity": 5,
        "unitPrice": 800,
        "amount": 4000
      }
    ],
    "subtotal": 8500,
    "taxRate": 19,
    "taxAmount": 1615,
    "total": 10115,
    "currency": "EUR",
    "paymentTerms": "Net 30",
    "notes": "Bank transfer to DE89 3704..."
  }
}
3

Use the data

The response is ready to pipe into your accounting system, spreadsheet, or database. Here are a few ideas:

JavaScript — sum line items
const res = await fetch("https://api.contexa.works/api/v1/invoice", {
  method: "POST",
  headers: { "x-rapidapi-key": "YOUR_API_KEY" },
  body: formData,
})
const { data } = await res.json()

// Access individual fields
console.log(data.vendor.name)       // "Acme Design Studio"
console.log(data.total)             // 10115
console.log(data.currency)          // "EUR"

// Iterate line items
for (const item of data.lineItems) {
  console.log(`${item.description}: ${item.amount}`)
}
Python — push to database
import requests

r = requests.post(
    "https://api.contexa.works/api/v1/invoice",
    headers={"x-rapidapi-key": key},
    files={"file": open("invoice.pdf", "rb")},
)
invoice = r.json()["data"]

db.execute(
    "INSERT INTO invoices (number, vendor, total, currency) VALUES (?, ?, ?, ?)",
    (invoice["invoiceNumber"], invoice["vendor"]["name"],
     invoice["total"], invoice["currency"]),
)
Tip: Use the prompt parameter to customize extraction — e.g. "Focus on line items only" or "Convert all amounts to pence".
TermsPrivacyContact