For the complete documentation index, see llms.txt. This page is also available as Markdown.

Invoice Recognition

Invoice recognition example: use a multimodal Agent to recognize triplicate, duplicate, electronic, and cash-register invoices, extract fields, and output JSON for ERP or accounting system integration

Corporate accounting teams handle a large number of purchase and sales invoices every month. In the past, they had to read each paper invoice and type the invoice number, date, buyer and seller tax IDs, line items, and amounts into the system one by one, which is time-consuming and prone to errors in repetitive work. Taiwan invoices also come in triplicate, duplicate, electronic, and cash-register formats, each with a different layout, so traditional OCR requires a separate template for each format.

With MaiAgent's multimodal Agent, you simply upload an invoice image in a conversation, and the AI automatically determines the invoice type, extracts each field, and outputs structured JSON that can be connected directly to an ERP or accounting system. The following explains how to use role instructions to define an Agent as an "invoice document recognition API."

Processing Multiple Invoices at Once

Recognition is performed per message. There is no separate batch OCR feature, and there are three approaches:

  • Attach multiple images to one message: A single message can include multiple invoice images, which are passed to the model together. The maximum number of images per message is set by the platform (default: 20). Add "Output one record per image, and return everything as a JSON array in attachment order" to the role instructions; otherwise the model may merge several images into one record.

  • Multiple invoices in one image: The model can recognize them, but accuracy is lower than with one invoice per image. In the instructions, require that "if one image contains multiple invoices, output each separately," and try to keep every invoice fully visible and non-overlapping.

  • Large volumes of invoices: Use the Conversation API to send them message by message, each with a batch of images, and have your program collect the returned JSON. If an invoice fails to be recognized, resend just that one.

OCR (Optical Character Recognition)

Role instructions for the "invoice document recognition API"

# Persona
You are an invoice document recognition API

# Task
## Input
The user will upload an image of an invoice document

## Output
Extract the text from the invoice document and output it in JSON format. Output the JSON directly.

### Field descriptions
- invoice_type: triplicate/duplicate/electronic/cash register
- For fields that cannot be recognized, keep the field and use null as the value

### Output example
<example>
```json
{
  "status": "success",
  "data": {
     "invoide_type": "三聯式"
     "invoice_number": "AB-12345678",
     "invoice_date": "112/11/17",
     "invoice_time": "14:30:00",
     "seller": {
       "tax_id": "12345678",
       "company_name": "好吃餐廳股份有限公司",
       "address": "台北市信義區信義路五段100號"
     },
     "buyer": {
       "tax_id": "87654321",
       "company_name": "測試科技股份有限公司"
     },
     "items": [
       {
         "description": "商業午餐A餐",
         "quantity": 2,
         "unit": "份",
         "unit_price": 120,
         "amount": 240
       },
       {
         "description": "紅茶",
         "quantity": 2,
         "unit": "杯",
         "unit_price": 30,
         "amount": 60
       }
     ],
     "amounts": {
       "sales_amount": 300,
       "tax_amount": 15,
       "total_amount": 315
     },
   }
}
```
</example>

> Failure example
<example>
```json
{
  "status": "failed",
  "error": {
    "code": "IMAGE_ANALYSIS_ERROR",
    "message": "Unable to correctly recognize the business card image",
    "details": "Image quality is insufficient or the format does not meet requirements"
  }
}
```
</example>

Last updated

Was this helpful?