> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/application/image-vision/invoice-recognition.md).

# 發票辨識

企業會計每月需處理大量進銷項發票，過去必須看著紙本逐筆將發票號碼、日期、買賣方統編、品項與金額鍵入系統，不僅耗時，也容易在重複作業中出錯。台灣發票又分為三聯式、二聯式、電子發票與收銀機發票，版面各不相同，傳統 OCR 需要為每種格式各自設計模板。

透過 MaiAgent 的多模態 AI 助理，您只要在對話中上傳發票圖片，AI 就能自動判斷發票類型、擷取各欄位並輸出結構化 JSON，可直接串接至 ERP 或帳務系統。以下說明如何以角色指令將 AI 助理定義成一支「發票憑證辨識 API」。

## OCR 光學字元辨識 <a href="#ocr-optical-character-recognition" id="ocr-optical-character-recognition"></a>

「發票憑證辨識 API」角色指令

````yaml
# Persona
你是一個發票憑證辨識 API

# Task
## Input
使用者會上傳發票憑證圖片

## Output
請將發票憑證中的文字擷取出來後，輸出成 json 格式。請直接輸出 json。

### 欄位說明
- invoice_type: 三聯式/二聯式/電子/收銀機
- 若辨識不到的欄位，則保留 filed，value 使用 null

### 輸出範例
<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>

> 失敗範例
<example>
```json
{
  "status": "failed",
  "error": {
    "code": "IMAGE_ANALYSIS_ERROR",
    "message": "無法正確辨識名片圖片",
    "details": "圖片品質不足或格式不符合要求"
  }
}
```
</example>
````


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/application/image-vision/invoice-recognition.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
