今日已更新 129 条资讯 | 累计 29863 条内容
关于我们

Extracting structured data from invoices and contracts with one API call

Mediavox 2026年07月26日 02:13 5 次阅读 来源:Dev.to

Extracting structured data from invoices and contracts with one API call 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. The problem 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. The approach Instead of building N parsers, I use a single multimodal AI endpoint that: Receives the file (PDF, image, DOCX — up to 20MB) Classifies the document type automatically Extracts named entities (vendor, amounts, dates, line items) Returns a structured JSON response Keeps a session open for follow-up questions Code (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 Follow-up questions (same session) 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

本文内容来源于互联网,版权归原作者所有
查看原文