DocuSense

AI Document Intelligence API

T4 · W-2 · P60 · P45 · EU Payslips · Invoices · Bank Statements

Base URLhttps://api.stackapi.dev/api/v1
MethodsPOST
File Inputbase64 · PDF · JPG · PNG · WEBP
AuthJWT · RapidAPI · APILayer
EngineAI Vision · Structured Extraction
Max File Size10 MB

Authentication

DocuSense supports three authentication methods.

# RapidAPI (automatic proxy)
X-RapidAPI-Proxy-Secret: your-secret

# APILayer
X-Apilayer-Key: your-key

# Direct (JWT Bearer)
Authorization: Bearer your-jwt-token

How It Works

Send any document as a base64-encoded string. DocuSense uses GPT-4o to read and extract structured data from both text-based and scanned documents.

# 1. Convert your file to base64 (PowerShell)
$bytes  = [System.IO.File]::ReadAllBytes("C:\path\to\document.pdf")
$base64 = [Convert]::ToBase64String($bytes)

# 2. Send to the API
POST /api/v1/documents/invoice
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType":   "application/pdf",
  "language":   "en"
}

Endpoints

Invoice Extraction

Extracts invoice number, date, vendor, buyer, line items, subtotal, taxes (GST, HST, TVA, VAT), and total from any invoice. Supports Canadian, US, and European invoices.

POST /api/v1/documents/invoice
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "language": "en"
}
View Response Schema
{
  "success": true,
  "data": {
    "invoiceNumber": "INV-2024-001",
    "invoiceDate": "2024-01-15",
    "dueDate": "2024-02-15",
    "vendor": { "name": "Acme Inc.", "address": "123 Main St", "taxNumber": "GST 123456789" },
    "buyer": { "name": "Client Corp", "address": "456 Oak Ave" },
    "lineItems": [
      { "description": "Consulting services", "quantity": 10, "unitPrice": 150.00, "amount": 1500.00 }
    ],
    "subtotal": 1500.00,
    "taxLines": [{ "name": "GST", "rate": 5, "amount": 75.00 }],
    "total": 1575.00,
    "currency": "CAD"
  }
}

Bank Statement

PRO+

Extracts account holder, institution, period, opening/closing balance, and up to 50 transactions with category inference.

POST /api/v1/documents/bank-statement
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "language": "fr"
}

Generic Extraction

Extract any custom fields from any document. Pass a list of field names and DocuSense returns their values.

POST /api/v1/documents/extract
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "fields": ["name", "date", "amount", "address"],
  "language": "en"
}

T4 Slip (Canada)

PRO+

Extracts all official CRA T4 boxes: employment income (box 14), CPP/RRQ (16/17), EI (18), income tax deducted (22), and more. SIN is always masked.

POST /api/v1/documents/t4
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "taxYear": 2024,
  "language": "fr"
}
View Response Schema
{
  "success": true,
  "data": {
    "taxYear": 2024,
    "employerName": "Acme Corp Inc.",
    "payrollAccountNumber": "123456789RP0001",
    "employeeName": "John Doe",
    "socialInsuranceNumber": "***-***-456",
    "province": "QC",
    "boxes": {
      "box14": 75000.00,
      "box16": 3799.80,
      "box18": 1049.12,
      "box22": 18500.00,
      "box24": 61500.00,
      "box26": 68500.00
    }
  }
}

W-2 Form (USA)

PRO+

Extracts all IRS W-2 boxes: wages (box 1), federal tax withheld (box 2), Social Security, Medicare, box 12 codes, state wages, and more. SSN is always masked.

POST /api/v1/documents/w2
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "taxYear": 2024,
  "language": "en"
}
View Response Schema
{
  "success": true,
  "data": {
    "taxYear": 2024,
    "employerName": "Acme Corporation",
    "socialSecurityNumber": "***-**-6789",
    "boxes": {
      "box1": 85000.00,
      "box2": 14500.00,
      "box3": 85000.00,
      "box4": 5270.00,
      "box5": 85000.00,
      "box6": 1232.50
    },
    "state": "NY"
  }
}

European Payslip

PRO+

Extracts payslip data for 8 EU countries with country-specific fields. France: CSG/CRDS, URSSAF. Germany: Lohnsteuer, Kirchensteuer. Belgium: précompte professionnel.

POST /api/v1/documents/paystub-eu
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "language": "fr",
  "country": "FR"    // FR | BE | DE | NL | CH | IT | ES | LU
}
View Response Schema
{
  "success": true,
  "data": {
    "country": "FR",
    "period": "2024-03",
    "employer": { "name": "Société Exemple SAS", "registrationNumber": "SIRET 123 456 789 00010" },
    "employee": { "name": "Marie Dupont", "socialSecurityNumber": "***-***-4567", "jobTitle": "Ingénieure" },
    "earnings": { "grossSalary": 4500.00, "baseSalary": 4200.00 },
    "deductions": {
      "healthInsurance": 315.00,
      "pension": 382.50,
      "csg": 387.90,
      "crds": 56.25,
      "totalDeductions": 1141.65
    },
    "netSalary": 3358.35,
    "currency": "EUR"
  }
}

P60 — End of Year Certificate (UK)

PRO+

Extracts HMRC P60 fields: total pay in year, total tax deducted, NI contributions (employee + employer), NI category, student loan deductions. NI number is always masked.

POST /api/v1/documents/p60
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "language": "en"
}
View Response Schema
{
  "success": true,
  "data": {
    "taxYear": "2024-25",
    "employerName": "UK Company Ltd",
    "payeReference": "123/AB456",
    "employeeName": "James Smith",
    "nationalInsuranceNumber": "**-**-**-**-C",
    "taxCode": "1257L",
    "totalPayInYear": 52000.00,
    "totalTaxDeducted": 9486.00,
    "nationalInsurance": {
      "niCategory": "A",
      "employeeNI": 3985.92,
      "employerNI": 5698.56
    }
  }
}

P45 — Leaving Work Certificate (UK)

PRO+

Extracts HMRC P45 fields: date of leaving, tax code, total pay and tax to date, week 1/month 1 indicator, and new employer details when present.

POST /api/v1/documents/p45
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "language": "en"
}

Avis d'imposition (France & Belgium)

ULTRA+

Extracts the French avis d'imposition or Belgian avertissement-extrait de rôle: taxable income by category, gross/net tax, tax credits, balance due or refund, effective and marginal rates.

POST /api/v1/documents/avis-imposition
{
  "fileBase64": "JVBERi0xLjc...",
  "mimeType": "application/pdf",
  "language": "fr"
}
View Response Schema
{
  "success": true,
  "data": {
    "country": "FR",
    "taxYear": 2024,
    "referenceAvis": "2024-XXXXXXXXXX",
    "taxpayer": { "name": "Jean Martin", "numberOfShares": 2.5 },
    "income": {
      "totalNetIncome": 48500.00,
      "salaryIncome": 52000.00,
      "referenceIncome": 54200.00
    },
    "tax": {
      "grossTax": 8460.00,
      "taxCredits": 1200.00,
      "netTax": 7260.00,
      "balanceDue": 1840.00,
      "isRefund": false,
      "effectiveRate": 14.97,
      "marginalRate": 30.00
    }
  }
}

Error Handling

All errors follow a consistent JSON envelope:

{
  "success": false,
  "error": {
    "code": "EXTRACTION_ERROR",
    "message": "Document processing timed out"
  }
}
400Invalid base64, unsupported MIME type, or file type mismatch
401Unauthorized — missing or invalid API key
403Insufficient plan — upgrade required
413File too large — maximum 10 MB
422Extraction failed — check file quality and retry
429Rate limit exceeded