Key Extraction v3 · ตัวอย่าง

ใบแจ้งหนี้ / ใบกำกับภาษี

ระบบบัญชีดึงข้อมูลใบแจ้งหนี้ PDF อัตโนมัติ — เลขที่เอกสาร ผู้ขาย รายการ และยอดรวม พร้อม bounding box สำหรับตรวจทานบนหน้าเอกสาร

ตารางใน schema

ใส่ line_items เป็น array ของ object ไม่ต้องมี listConfig ใบกำกับภาษีหลายหน้าส่งได้ทั้งไฟล์ หรือเลือกหน้าด้วย inputs[].pages
Endpoint
POST /api/v3/key-extract/jobs
ไฟล์
invoice.pdf
ฟิลด์
11 ฟิลด์ · required 2
ตาราง
line_items[]
หลักฐาน
bbox ต่อฟิลด์ (ค่าเริ่มต้น)
ผลลัพธ์
ตัวอย่างประกอบ

data_schema

json
{
"type": "object",
"additionalProperties": false,
"properties": {
"invoice_no": {
"type": "string",
"description": "เลขที่ใบแจ้งหนี้ / ใบกำกับภาษี"
},
"invoice_date": {
"type": "string",
"format": "date",
"description": "วันที่ออกเอกสาร"
},
"seller_name": {
"type": "string",
"description": "ชื่อผู้ขาย"
},
"seller_tax_id": {
"type": "string",
"description": "เลขประจำตัวผู้เสียภาษีของผู้ขาย 13 หลัก"
},
"subtotal": {
"type": "number",
"description": "ยอดก่อน VAT"
},
"vat": {
"type": "number",
"description": "ภาษีมูลค่าเพิ่ม"
},
"total": {
"type": "number",
"description": "ยอดรวมรวม VAT"
},
"line_items": {
"type": "array",
"description": "รายการสินค้าหรือบริการ",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"description": {
"type": "string"
},
"quantity": {
"type": "number"
},
"unit_price": {
"type": "number"
},
"amount": {
"type": "number"
}
}
}
}
},
"required": [
"invoice_no",
"total"
]
}

Request

อัปโหลดไฟล์ สร้างงานด้วย schema ด้านบน poll จนจบ แล้วดึงผล — ตัวอย่างนี้ส่ง instructions เพิ่มด้วย

import json, time, requests
API = "https://backend.aksonocr.com/api/v3/key-extract"
headers = {"X-API-Key": "<YOUR_API_KEY>"}
schema = json.load(open("schema.json", encoding="utf-8"))
with open("invoice.pdf", "rb") as document:
file_id = requests.post(f"{API}/files", headers=headers, files={"files": document}).json()["files"][0]["id"]
job_id = requests.post(
f"{API}/jobs",
headers={**headers, "Idempotency-Key": "invoice-001"},
json={
"inputs": [{"file_id": file_id}],
"data_schema": schema,
"instructions": "ยอดเงินเป็นตัวเลขไม่มีจุลภาค วันที่แปลงเป็น ค.ศ. รูปแบบ YYYY-MM-DD",
},
).json()["id"]
while requests.get(f"{API}/jobs/{job_id}", headers=headers).json()["status"] not in {
"completed", "failed", "cancelled", "expired"
}:
time.sleep(2)
result = requests.get(f"{API}/jobs/{job_id}/result", headers=headers).json()
print(result["data"])
print(result["validation"])

ผลลัพธ์

ตัวอย่างประกอบ

ค่าด้านล่างแสดงรูปแบบผลลัพธ์ ไม่ได้มาจากเอกสารจริง
json
{
"needs_review": false,
"data": {
"invoice_no": "INV-2026-0142",
"invoice_date": "2026-09-06",
"seller_name": "บริษัท ตัวอย่าง จำกัด",
"seller_tax_id": "0105551234567",
"subtotal": 10000,
"vat": 700,
"total": 10700,
"line_items": [
{
"description": "บริการ OCR",
"quantity": 1,
"unit_price": 10000,
"amount": 10000
}
]
},
"field_metadata": {
"/invoice_no": {
"status": "verified",
"confidence": 0.98,
"regions": [
{
"page": 1,
"bbox": [
0.684,
0.072,
0.912,
0.104
],
"text": "INV-2026-0142"
}
]
},
"/total": {
"status": "verified",
"confidence": 0.97,
"regions": [
{
"page": 1,
"bbox": [
0.802,
0.712,
0.928,
0.741
],
"text": "10,700.00"
}
]
}
},
"validation": {
"missing_required": [],
"below_threshold": []
}
}

ความหมายของ status, confidence และ bbox อยู่ที่ การดึงผลลัพธ์