# Extracting structured data from invoices and contracts with one API call

> Source: <https://dev.to/mediavox/extracting-structured-data-from-invoices-and-contracts-with-one-api-call-n5p>
> Published: 2026-07-25 18:13:52+00:00

I've been working on a document analysis API and wanted to share a pattern that saved me from writing custom parsers for every document type my clients throw at me.

If you work with LATAM businesses, you know the pain: invoices in PDF (sometimes scanned), contracts in Word, receipts as phone photos. Every client has a different format. Building regex parsers for each one is a nightmare that breaks every time the layout changes slightly.

Instead of building N parsers, I use a single multimodal AI endpoint that:

``` python
import requests

# Upload and analyze in one call
with open("invoice.pdf", "rb") as f:
    response = requests.post(
        "https://mediavox.co/mvai/api/v1/documents/analyze",
        files={"file": f},
        data={
            "api_key": "your_key_here",
            "question": "Extract: vendor name, tax ID, invoice number, date, line items with quantities and prices, subtotal, tax, total."
        },
        timeout=60
    )

result = response.json()

print(result["answer"])       # Human-readable summary
print(result["entities"])     # Structured: [{type: "vendor", value: "..."}]
print(result["document_type"]) # "factura", "contrato", "recibo"...
print(result["session_id"])   # For follow-up questions
```

The session persists the document context, so you can ask clarifying questions without re-uploading:

```
follow_up = requests.post(
    "https://mediavox.co/mvai/api/v1/chat",
    json={
        "api_key": "your_key_here",
        "question": "What are the payment terms?",
        "session_id": result["session_id"]
    }
)

print(follow_up.json()["answer"])
# "Payment terms: 30 days net. Due date: August 15, 2026."
```

The AI answers from the document only — no hallucinations from external knowledge.

Input: a crumpled photo of a Colombian restaurant receipt (low light, tilted)

```
{
  "document_type": "recibo",
  "entities": [
    {"type": "vendor", "value": "Restaurante El Portal", "confidence": 0.94},
    {"type": "tax_id", "value": "901234567-8", "confidence": 0.91},
    {"type": "total", "value": "98700", "confidence": 0.97},
    {"type": "tax", "value": "15800", "confidence": 0.89},
    {"type": "date", "value": "2026-06-28", "confidence": 0.95}
  ],
  "integrity": {
    "subtotal_matches_items": true,
    "tax_calculation_correct": true
  }
}
```

The `integrity`

check catches arithmetic mismatches automatically — useful for expense auditing.

If you use n8n, there's a community node (`n8n-nodes-mediavox`

) that wraps all of this. Or use HTTP Request nodes directly — the API is straightforward REST.

I published a ready-to-use workflow template: [Extract invoice details and ask follow-ups](https://mediavox.co/mvdevportal/static/n8n/documentpower-analyze-invoice.json) — import it and replace the file path.

Free tier: 100 requests/month. Enough to test with real documents.

`n8n-nodes-mediavox`

on npm*Built this for LATAM businesses dealing with messy paperwork. If you're processing documents in Spanish/Portuguese and tired of custom parsers, this might save you time.*
