Key Extraction · API v3

เริ่มต้นใช้งาน

ดึงฟิลด์แรกพร้อม bounding box ภายในไม่กี่นาที — อัปโหลดไฟล์ สร้างงาน แล้ว poll จนเสร็จ

ก่อนเริ่ม

  1. 1สมัครที่ dashboard.aksonocr.com และสร้าง API key
  2. 2เตรียม PDF, JPEG, PNG, WebP, HEIC หรือ HEIF ไม่เกิน 25 MB ต่อไฟล์
  3. 3กำหนด JSON Schema ของฟิลด์ที่ต้องการดึง (หรือสร้างเทมเพลตบน Dashboard)

งาน Key Extraction แรก

ขั้นที่ 1: POST /api/v3/key-extract/files ได้ file_id ขั้นที่ 2: POST /api/v3/key-extract/jobs ต้องมี header Idempotency-Key และส่ง data_schema หรือ template อย่างใดอย่างหนึ่ง

import time
import requests
API = "https://backend.aksonocr.com/api/v3/key-extract"
headers = {"X-API-Key": "<YOUR_API_KEY>"}
with open("invoice.pdf", "rb") as document:
upload = requests.post(f"{API}/files", headers=headers, files={"files": document})
upload.raise_for_status()
file_id = upload.json()["files"][0]["id"]
job = requests.post(
f"{API}/jobs",
headers={**headers, "Idempotency-Key": "first-extract-001"},
json={
"inputs": [{"file_id": file_id}],
"data_schema": {
"type": "object",
"additionalProperties": False,
"properties": {
"invoice_no": {"type": "string", "description": "เลขที่ใบแจ้งหนี้"},
"total": {"type": "number", "description": "ยอดรวมรวม VAT"},
},
"required": ["invoice_no"],
},
"output": {"evidence": "bbox"},
},
)
job.raise_for_status()
job_id = job.json()["id"]
while True:
status = requests.get(f"{API}/jobs/{job_id}", headers=headers).json()
if status["status"] in {"completed", "failed", "cancelled", "expired"}:
break
time.sleep(2)
if status["status"] != "completed":
raise RuntimeError(status.get("error") or status["status"])
result = requests.get(f"{API}/jobs/{job_id}/result", headers=headers).json()
print(result["data"])
print(result["field_metadata"]["/invoice_no"]["regions"])

ตัวอย่างคำตอบตอนรับงาน

json
{
"id": "ext_01JBY7...",
"status": "queued",
"created_at": "2026-09-06T10:00:00Z",
"configuration": {
"output": { "evidence": "bbox" },
"review_threshold": 0.8
},
"links": {
"self": "/api/v3/key-extract/jobs/ext_01JBY7...",
"result": "/api/v3/key-extract/jobs/ext_01JBY7.../result"
},
"request_id": "req_01J..."
}

Dashboard

ถ้ายังไม่พร้อมเขียนโค้ด ไปที่ Dashboard → Key Extraction อัปโหลดเอกสาร กำหนดฟิลด์ แล้วดู overlay bbox ได้ทันที จากนั้นคัดลอกโค้ด API v3 ไปใช้ในแอป

ขั้นถัดไป