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

สัญญา

สัญญาและข้อตกลง — คู่สัญญา วันเริ่ม วันสิ้นสุด มูลค่า และเลขที่อ้างอิง สัญญามักยาวหลายหน้า ค่าแต่ละตัวบอกหน้าที่พบใน regions[].page

Endpoint
POST /api/v3/key-extract/jobs
ไฟล์
contract.pdf
ฟิลด์
7 ฟิลด์ · required 2
ตาราง
ไม่มี
หลักฐาน
bbox ต่อฟิลด์ (ค่าเริ่มต้น)
ผลลัพธ์
ตัวอย่างประกอบ

data_schema

json
{
"type": "object",
"additionalProperties": false,
"properties": {
"title": {
"type": "string",
"description": "ชื่อสัญญา"
},
"contract_no": {
"type": "string",
"description": "เลขที่สัญญา"
},
"party_1": {
"type": "string",
"description": "ชื่อนิติบุคคลหรือบุคคลฝ่ายที่หนึ่ง"
},
"party_2": {
"type": "string",
"description": "ชื่อนิติบุคคลหรือบุคคลฝ่ายที่สอง"
},
"effective_date": {
"type": "string",
"description": "วันที่สัญญามีผล"
},
"end_date": {
"type": "string",
"description": "วันสิ้นสุดสัญญา"
},
"value": {
"type": "number",
"description": "มูลค่าสัญญา (บาท)"
}
},
"required": [
"party_1",
"party_2"
]
}

Request

อัปโหลดไฟล์ สร้างงานด้วย schema ด้านบน poll จนจบ แล้วดึงผล

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("contract.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": "contract-001"},
json={
"inputs": [{"file_id": file_id}],
"data_schema": schema,
},
).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": {
"title": "สัญญาจ้างบริการประมวลผลเอกสาร",
"contract_no": "CT-2026/017",
"party_1": "บริษัท ผู้ว่าจ้าง ตัวอย่าง จำกัด",
"party_2": "บริษัท ผู้รับจ้าง ตัวอย่าง จำกัด",
"effective_date": "1 พฤศจิกายน 2569",
"end_date": "31 ตุลาคม 2570",
"value": 360000
},
"field_metadata": {
"/party_2": {
"status": "verified",
"confidence": 0.97,
"regions": [
{
"page": 1,
"bbox": [
0.214,
0.262,
0.611,
0.284
],
"text": "บริษัท ผู้รับจ้าง ตัวอย่าง จำกัด"
}
]
},
"/end_date": {
"status": "verified",
"confidence": 0.93,
"regions": [
{
"page": 3,
"bbox": [
0.402,
0.518,
0.597,
0.541
],
"text": "31 ตุลาคม 2570"
}
]
}
},
"validation": {
"missing_required": [],
"below_threshold": []
}
}

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