High-Accuracy Invoice OCR API for Go Applications
Achieve 99.7%+ accuracy on line-item extraction and get structured JSON responses in under 1500ms.

Why Invoice OCR is Difficult
Generic OCR tools fail on invoices due to their high layout variance. Unlike passports or licenses, invoices lack a standardized format, leading to inconsistent table structures, column orders, and field locations. Parsing this requires complex, brittle RegEx patterns that break with each new vendor template. Furthermore, image quality issues from scans or photos, such as low resolution, skew, and shadows, degrade accuracy significantly. Open-source engines like Tesseract often misinterpret table rows or fail to associate line items with their correct totals, creating a high-cost maintenance burden for any serious Accounts Payable automation system.
Enterprise-Grade Extraction with StructOCR
StructOCR leverages pre-trained Deep Learning models specifically fine-tuned on millions of diverse invoice layouts, making it an ideal solution for accounts payable ocr. Our API bypasses the need for manual templating. Upon receiving an image, our system performs automatic pre-processing, including deskewing, denoising, and contrast enhancement. The model then identifies and extracts key-value pairs, headers, and complex table data, including multi-line item descriptions. Unlike Tesseract, which returns a raw text dump, StructOCR delivers a predictable, standardized JSON output with validated fields, ready for direct integration into your ERP or accounting software, thereby streamlining finance workflows.
Production Use Cases
- Accounts Payable Automation: Automate your entire AP workflow by ingesting invoices from any source and posting structured data directly to your ERP.
- Expense Management: Process employee expense reports in real-time by extracting vendor, total amount, and line items from submitted receipts and invoices.
- Supply Chain Auditing: Verify and audit thousands of supplier invoices for compliance and pricing accuracy without manual intervention.
Live Demo: Invoice extractor
No registration required. Upload a file to test the extraction.
Drop files here or click to browse
JPG · PNG · WebP · up to 500 files · max 4.5 MB each
Implementation: Go (Golang)
The following Go code provides a robust implementation. It handles file reading, Base64 encoding, and parses the complex nested JSON structure (line items, financials) into native Go structs.
Prerequisite: Go 1.16+
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
// 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
// 👉 https://structocr.com/register
// --- Struct Definitions for JSON Parsing ---
type InvoiceResponse struct {
Success bool `json:"success"`
Data InvoiceData `json:"data"`
Error string `json:"error,omitempty"`
}
type InvoiceData struct {
InvoiceNumber string `json:"invoice_number"`
Date string `json:"date"`
Currency string `json:"currency"`
Merchant Merchant `json:"merchant"`
Financials Financials `json:"financials"`
LineItems []LineItem `json:"line_items"`
}
type Merchant struct {
Name string `json:"name"`
TaxID string `json:"tax_id"`
}
type Financials struct {
TotalAmount float64 `json:"total_amount"`
TaxAmount float64 `json:"tax_amount"`
}
type LineItem struct {
Description string `json:"description"`
Quantity float64 `json:"quantity"`
Amount float64 `json:"amount"`
}
func main() {
apiURL := "https://api.structocr.com/v1/invoice"
apiKey := "YOUR_API_KEY_HERE"
imagePath := "invoice.jpg" // Supports JPG, PNG
// 1. Read and Encode Image
imageBytes, err := os.ReadFile(imagePath)
if err != nil {
fmt.Printf("Error reading file: %v\n", err)
return
}
base64Image := base64.StdEncoding.EncodeToString(imageBytes)
// 2. Prepare Payload
payload, _ := json.Marshal(map[string]string{"img": base64Image})
// 3. Create Request
req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(payload))
if err != nil {
fmt.Printf("Request creation failed: %v\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", apiKey) // Required Header
// 4. Send Request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Network error: %v\n", err)
return
}
defer resp.Body.Close()
// 5. Parse Response
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
fmt.Printf("API Error (%d): %s\n", resp.StatusCode, string(body))
return
}
var result InvoiceResponse
if err := json.Unmarshal(body, &result); err != nil {
fmt.Printf("JSON Parse Error: %v\n", err)
return
}
if result.Success {
data := result.Data
fmt.Println("✅ Invoice Extracted Successfully!")
fmt.Printf("Invoice #: %s (Date: %s)\n", data.InvoiceNumber, data.Date)
fmt.Printf("Vendor: %s (Tax ID: %s)\n", data.Merchant.Name, data.Merchant.TaxID)
fmt.Printf("Total: %.2f %s\n", data.Financials.TotalAmount, data.Currency)
fmt.Println("\n--- Line Items ---")
for _, item := range data.LineItems {
fmt.Printf("- %s (Qty: %.0f) = %.2f\n", item.Description, item.Quantity, item.Amount)
}
} else {
fmt.Printf("Extraction failed: %s\n", result.Error)
}
}Technical Specs
- •Latency: < 4s (Average)
- •Uptime: 99.9% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Base64 Encoded)
- •Max File Size: 4.5MB
- •Output: JSON (Nested Structure)
Key Features
- •Table Extraction Engine: Accurately parses complex line items and tables without manual templating.
- •Financial Validation: Cross-validates subtotals, taxes, and grand totals to ensure mathematical accuracy.
- •Vendor Normalization: Automatically identifies merchants and extracts standardized tax IDs (VAT/EIN).
Sample JSON Output
StructOCR returns a normalized JSON object, regardless of the input image angle or quality.
{
"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
}
]
}
}Frequently Asked Questions
How does StructOCR compare to AWS Textract or Google Vision?
Unlike general-purpose OCR services that return raw text coordinates, StructOCR is a specialized model fine-tuned on millions of invoices. It returns a structured JSON object with pre-identified fields like `invoice_number`, `line_items`, and `merchant_name`, eliminating the need for complex post-processing and rule-based parsing.
Do you store the uploaded images?
No, images are processed in memory and deleted immediately after extraction. We do not persist any of your source data.
How do you handle blurry or low-quality images?
Our API includes an automatic image pre-processing engine that applies denoising, deskewing, and contrast enhancement to improve OCR accuracy on low-quality or blurry images before the extraction models are run.
You May Also Like
Related tutorials, platform guides, and comparisons
Node.js Invoice Parsing API
High-accuracy Node.js invoice parsing API for accounts payable automation. Upload an image for a free test! Extract line items, merchants, and financials into structured JSON output instantly.
C# Invoice OCR API
Upload an image for a free test! Integrate a high-accuracy Invoice OCR API into your C# application. Get structured JSON output for line items, totals, and merchant data. Eliminate Tesseract errors.
PHP Invoice Line Item OCR API
Struggling with manual invoice data entry? Our PHP invoice line item OCR API processes documents in <3s, outputting structured JSON. Upload an image for a free test! SOC2 compliant & AES-256 encrypted.
Java OCR Invoice API
Upload an invoice to try our live demo. High-accuracy Java OCR invoice API for accounts payable. Extract line items directly into JSON.
Python Invoice Line Item OCR API
Struggling with invoice line item extraction? Our Python OCR API delivers structured JSON in under 4s, ensuring 98.5% uptime and SOC2 compliance. Upload an image for a free test! Secure your data.
Go License Plate OCR API
Golang License Plate OCR tutorial. Upload an image for a free test! Accurately extract global license plates, native scripts, colors, and vehicle types.
Côte d'Ivoire Passport OCR with Node.js SDK
Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Côte d'Ivoire passports.
Colombia Cédula OCR Python SDK
Python Tutorial: Automate KYC in Colombia. Extract data from the Colombian Cédula de Ciudadanía using StructOCR Python SDK. Supports NUIP extraction and complex address parsing.
Colombia Passport OCR with Node.js SDK
Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Colombia passports.
Côte d'Ivoire Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Côte d'Ivoire passports with a server-side integration.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Invoice OCR API Integration for Bolt.new
Learn how to integrate our Invoice OCR API into a Bolt.new app in under 5 minutes. Extract structured JSON effortlessly. Try our free live test now.
Add Invoice OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR invoice API using the Cursor AI code editor. Build accounts payable and expense tracking tools rapidly.
Add Invoice OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR invoice API into a Lovable.dev app. No backend required — just paste a prompt and add your API key.
Add Invoice OCR to Your Replit App in 5 Minutes
Step-by-step guide to integrating the StructOCR invoice API into a Replit application. Build accounts payable and expense tracking tools using Replit Agent and Secrets.
Template-Based OCR vs. StructOCR API for Invoice Processing
Why traditional zonal/template-based OCR fails at processing vendor invoices, and how layout-agnostic AI APIs instantly extract line items and totals.
Add Invoice OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR invoice API into a v0 by Vercel app. Build accounts payable and expense tracking tools with zero backend.
From tutorial to production in 5 minutes.
You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.