Invoice OCR

Automate your Accounts Payable (AP) and expense workflows with our intelligent Invoice OCR API. Unlike traditional templates, our AI understands the semantic structure of documents, allowing it to extract line items, tax breakdowns, and vendor details from any invoice layout. Perfect for ERP integrations, bookkeeping software, and receipt scanning apps.


Endpoint

POSThttps://api.structocr.com/v1/invoice

Request Parameters

Note: Currently supports image inputs (JPG, PNG). For multi-page PDFs, we recommend converting the first page to an image before sending.

ParameterInRequiredDescription
x-api-keyHeaderRequiredYour unique API key generated from the dashboard.
Content-TypeHeaderRequiredMust be set to application/json.
imgBody (JSON)RequiredThe Base64 encoded string of the invoice/receipt image.
  • Supports standard Data URI scheme
  • Supports raw Base64 strings
  • Max file size: 4.5MB
  • Formats: JPG, PNG, WebP

Response Schema

The API returns a nested JSON object designed for accounting systems. Fields are grouped by context (`merchant`, `customer`, `financials`, `line_items`).

FieldDescription
Root Metadata
typeDocument type, typically returns 'invoice' or 'receipt'.
invoice_numberUnique identifier/reference number of the document.
dateInvoice issue date (YYYY-MM-DD).
due_datePayment due date (YYYY-MM-DD), helpful for cash flow management.
currencyISO 4217 currency code (e.g., 'USD', 'EUR').
Merchant (Vendor)
merchant.nameName of the supplier or vendor.
merchant.tax_idTax registration number (VAT, GST, EIN, ABN).
merchant.ibanInternational Bank Account Number (Critical for EU/UK invoices).
Financials
financials.total_amountThe final total amount due (including tax).
financials.tax_amountTotal tax amount extracted from the summary.
financials.subtotalNet amount before tax.
Line Items (Array)
line_items[].descriptionDescription of the product or service.
line_items[].quantityCount or hours.
line_items[].unit_pricePrice per unit.
line_items[].amountLine total (Quantity * Unit Price).

Code Examples

Request Implementation

curl -X POST https://api.structocr.com/v1/invoice \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "img": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
  }'

Success Response (200 OK)

JSON EXAMPLE
{
  "success": true,
  "data": {
    "type": "invoice",
    "invoice_number": "INV-2026-001",
    "date": "2026-01-15",
    "due_date": "2026-02-15",
    "currency": "USD",
    "merchant": {
      "name": "AWS Web Services",
      "address": "410 Terry Ave N, Seattle, WA",
      "tax_id": "EIN-12-3456789",
      "iban": null
    },
    "customer": {
      "name": "Acme Corp Inc.",
      "tax_id": "987654321"
    },
    "financials": {
      "subtotal": 100,
      "tax_amount": 10,
      "total_amount": 110
    },
    "line_items": [
      {
        "description": "EC2 Instance Usage",
        "quantity": 1,
        "unit_price": 80,
        "amount": 80
      },
      {
        "description": "S3 Storage",
        "quantity": 1,
        "unit_price": 20,
        "amount": 20
      }
    ]
  }
}

Error Responses

400 Bad Request

{
  "status": 400,
  "code": "INVALID_REQUEST_FORMAT",  
  // or "INVALID_JSON", "INVALID_BASE64_FORMAT"
  "message":"The image data in 'img' field is malformed. Please check for illegal characters (spaces, newlines) or incorrect Base64 encoding."
}

402 Payment Required

Each successful invoice extraction costs 3 credits.

{
  "success": false,
  "error": "INSUFFICIENT_CREDITS",
  "message": "Your account balance is insufficient to complete this operation."
}

422 Unprocessable Entity

Returned if the AI safety filter blocks the content.

{
  "success": false,
  "error": "CONTENT_POLICY_VIOLATION",
  "message": "The document content could not be processed due to safety policies."
}

503 Service Unavailable

{
  "success": false,
  "error": "SYSTEM_BUSY",
  "message": "StructOCR is currently processing a high volume of requests..."
}

Status Code Definitions

CodeError CodeDescription
200SUCCESSRecognition success
400INVALID_REQUEST_FORMATInvalid payload or corrupted Base64. Ensure the image string has no whitespace, newlines, or illegal characters.
402INSUFFICIENT_CREDITSInsufficient credits (Cost: 3/req)
413FILE_TOO_LARGEDecoded image exceeds 4.5MB
422CONTENT_POLICY_VIOLATIONAI safety/policy block
503SYSTEM_BUSYAPI Rate limit reached