เอกสาร API
ทุกอย่างที่ต้องใช้ในการเชื่อมต่อ T&P AITECH OCR กับระบบของคุณ
การยืนยันตัวตน
ส่ง API key ใน header Authorization ทุกคำขอ สร้างคีย์ได้ที่หน้า API Keys ในแดชบอร์ด
Authorization: Bearer tnp_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
อ่านเอกสาร
POSThttp://localhost:3000/api/v1/ocr
ส่งไฟล์แบบ multipart/form-data หรือ JSON ระบบจะคืนผลลัพธ์ในคำขอเดียวกัน
พารามิเตอร์
| ชื่อ | ชนิด | คำอธิบาย |
|---|---|---|
file | file | ไฟล์เอกสาร (PNG, JPG, WEBP, PDF) — ใช้กับ multipart |
file_base64 | string | ไฟล์แบบ base64 หรือ data URL — ใช้กับ JSON |
file_url | string (https) | ลิงก์ HTTPS ของไฟล์ — ใช้กับ JSON |
mode | "text" | "extract" | text = อ่านทั้งหน้า (Markdown), extract = ดึงข้อมูลเป็น JSON (ค่าเริ่มต้น text) |
template | "auto" | "invoice" | "thai_id" | "passport" | "government_doc" | "custom" | เทมเพลตสำหรับโหมด extract (ค่าเริ่มต้น auto) |
fields | JSON array | ฟิลด์ที่ต้องการเมื่อ template = custom เช่น [{"name":"contract_no","description":"เลขที่สัญญา"}] |
curl -X POST http://localhost:3000/api/v1/ocr \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@invoice.jpg" \
-F "mode=extract" \
-F "template=invoice"เทมเพลต
เอกสารใดๆauto
ดึงข้อมูลสำคัญทั้งหมดอัตโนมัติ
items
ใบกำกับภาษี / ใบเสร็จinvoice
ผู้ขาย ผู้ซื้อ รายการ VAT ยอดรวม
document_titledocument_numberissue_dateseller_nameseller_tax_idseller_branchseller_addressbuyer_namebuyer_tax_idbuyer_addressline_itemssubtotaldiscountvat_ratevat_amountwithholding_taxtotalcurrencypayment_terms
บัตรประชาชนthai_id
เลข 13 หลัก ชื่อ วันเกิด ที่อยู่
id_numberprefix_thfirst_name_thlast_name_thprefix_enfirst_name_enlast_name_endate_of_birthreligionaddressissue_dateexpiry_datelaser_code
หนังสือเดินทางpassport
MRZ เลขพาสปอร์ต สัญชาติ วันหมดอายุ
document_typeissuing_countrypassport_numbersurnamegiven_namesnationalitydate_of_birthsexplace_of_birthissue_dateexpiry_datepersonal_numbermrz_line1mrz_line2
หนังสือราชการgovernment_doc
เลขที่ วันที่ เรื่อง เรียน ผู้ลงนาม
letter_numberissuing_agencydatesubjectrecipientreferencesenclosuressummarysigner_namesigner_positioncontact
กำหนดเองcustom
ระบุฟิลด์ที่ต้องการเอง
ตัวอย่างผลลัพธ์
{
"id": "ocr_3f9a1c0e2b7d4a5f6e8c9b10",
"object": "ocr.result",
"mode": "extract",
"template": "invoice",
"pages": 1,
"model": "google/gemini-3.5-flash-lite",
"document_type": "Thai tax invoice / receipt",
"fields": {
"document_number": "INV-2026-0142",
"issue_date": "2026-10-15",
"seller_name": "บริษัท ตัวอย่าง จำกัด",
"seller_tax_id": "0105555000000",
"line_items": [
{
"description": "ค่าบริการ OCR",
"quantity": 1,
"unit_price": 1000,
"amount": 1000
}
],
"vat_amount": 70,
"total": 1070,
"currency": "THB"
},
"warnings": [],
"usage": {
"credits_used": 1,
"credits_remaining": 49,
"latency_ms": 3120
}
}รหัสข้อผิดพลาด
{ "error": { "code": "insufficient_credits", "message": "This request needs 3 credit(s)" } }| 400 | invalid_request | คำขอไม่ถูกต้อง |
| 401 | unauthorized | API key ไม่ถูกต้องหรือถูกยกเลิกแล้ว |
| 402 | insufficient_credits | เครดิตไม่พอ กรุณาเติมเครดิต |
| 413 | file_too_large | ไฟล์ใหญ่เกินไป |
| 413 | too_many_pages | จำนวนหน้าเกินกำหนด |
| 415 | unsupported_file | รองรับเฉพาะ PNG, JPG, WEBP และ PDF |
| 429 | rate_limited | ใช้งานถี่เกินไป กรุณาลองใหม่ภายหลัง |
| 429 | demo_limit | ครบจำนวนทดลองฟรีของวันนี้แล้ว สมัครฟรีเพื่อใช้งานต่อ |
| 502 | ocr_failed | อ่านเอกสารไม่สำเร็จ กรุณาลองใหม่ |
| 503 | not_configured | ระบบยังไม่ได้ตั้งค่า (ติดต่อผู้ดูแลระบบ) |
ข้อจำกัด
- อัปโหลดไฟล์โดยตรงได้สูงสุด 4 MB (ใช้ file_url สำหรับไฟล์ใหญ่สูงสุด 20 MB)
- PDF สูงสุด 30 หน้าต่อคำขอ
- 60 คำขอต่อนาทีต่อ API key
- 1 เครดิตต่อหน้า คืนเครดิตอัตโนมัติเมื่ออ่านไม่สำเร็จ