> 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/maiagent-user-guide/ja/work/image-vision/invoice-recognition.md).

# 請求書認識

請求書認識のアプリケーション例：マルチモーダル Agent で三聯式・二聯式・電子・レジ発行の発票（インボイス）を認識し、項目を抽出して JSON を出力、ERP や会計システムと連携します。

企業の経理部門では毎月大量の仕入・売上の発票を処理する必要があり、これまでは紙の発票を見ながら、発票番号、日付、売り手・買い手の統一編号、品目、金額を一件ずつシステムに入力していました。時間がかかるだけでなく、繰り返し作業の中で入力ミスも起こりやすくなります。台湾の発票は三聯式、二聯式、電子発票、レジ発行の発票に分かれ、それぞれレイアウトが異なるため、従来の OCR では形式ごとにテンプレートを設計する必要があります。

MaiAgent のマルチモーダル Agent を使えば、会話で発票の画像をアップロードするだけで、AI が発票の種類を自動的に判別し、各項目を抽出して構造化された JSON を出力します。出力した JSON は ERP や会計システムにそのまま連携できます。以下では、ロール指示によって Agent を「発票認識 API」として定義する方法を説明します。

## 複数の発票をまとめて処理する <a href="#multiple-invoices" id="multiple-invoices"></a>

認識は「1 つのメッセージ」を単位として行われ、独立したバッチ OCR 機能はありません。方法は次の 3 つです。

* **1 つのメッセージに複数の画像を添付する**：1 つのメッセージに複数の発票画像を添付して、まとめてモデルに渡せます。1 メッセージあたりの画像枚数の上限はプラットフォームの設定によります（デフォルトは 20 枚）。ロール指示に「画像 1 枚につき 1 件を出力し、全体を添付ファイルの順に JSON 配列で返す」と追記してください。追記しないと、モデルが複数の画像を 1 件にまとめてしまう場合があります。
* **1 枚の画像に複数の発票がある場合**：モデルは認識できますが、1 枚の画像に 1 枚の発票の場合より精度が下がります。指示に「同じ画像に複数の発票がある場合は、それぞれ別に出力する」と加え、各発票が全体として写り、重ならないようにできるだけ配置してください。
* **大量の発票**：[会話 API](https://docs.maiagent.ai/tech/api-integration/conversations-and-messages) を使って、画像をまとめたものを 1 メッセージずつ送信し、返された JSON をプログラムで収集します。認識に失敗した発票があれば、その 1 枚だけを再送します。

{% hint style="warning" %}
発票画像をナレッジベースにアップロードしても、ファイルが保存されてインデックスが作成されるだけで、認識は実行されず、JSON も生成されません。認識は必ず会話の中で行います。
{% endhint %}

## OCR（光学文字認識） <a href="#ocr-optical-character-recognition" id="ocr-optical-character-recognition"></a>

「発票認識 API」のロール指示

````yaml
# Persona
あなたは発票認識 API です

# Task
## Input
ユーザーが発票の画像をアップロードします

## Output
発票から文字を抽出し、json 形式で出力してください。json を直接出力してください。

### フィールドの説明
- invoice_type: 三聯式/二聯式/電子/レジ
- 認識できないフィールドは、フィールドを残し、値には 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/maiagent-user-guide/ja/work/image-vision/invoice-recognition.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
