PDF.chat API
โหลด PDF และ chat กับมันจากแอพของคุณเอง - ถามคำถามและได้รับคำตอบที่อ้างถึงหน้า, ในภาษา 100+ ค่าต่อหน้า, ไม่น่าแปลกใจ
รายละเอียด
PDF.chat API เป็นอินเทอร์เฟซ REST ขนาดเล็ก POST ใช้เอกสารเพื่อรับข้อมูลและรับงานกลับมาพร้อมข้อความของเอกสารและรายละเอียดของแต่ละหน้า (ข้อความ, ขอบเขต, ความมั่นใจ) จากนั้นคุณจะ POST คำถามที่ใช้กับงานนั้น และรับคำตอบที่มาจากเอกสาร โดยแต่ละคำถามจะอ้างอิงถึงหน้าที่มันมาจาก งานที่มีขนาด5หน้า หรือน้อยกว่า จะถูกส่งกลับมาในบรรทัด งานที่ใหญ่กว่า จะถูกส่งกลับมาทันทีพร้อมกับ pending สถานะที่คุณถามถึง done.
- ที่อยู่ URL พื้นฐาน:
https://pdf.chat - เอกสารใน: PDF, Word, PowerPoint, ข้อความและรูปภาพ (PNG, JPG, WEBP, GIF, BMP, TIFF)
- Chat ออก: คำตอบที่ใช้คำอ้างอิงจากหน้า; คำบันทึกผ่านทางจุดจบของประวัติศาสตร์
- ข้อความที่ถูกประมวลผลออก:
txt,md,docx,pdf,csv,json - เครื่องอ่าน:
cpu(เร็ว, พิมพ์เอกสาร) และvlm(อัจฉริยะระดับพรีเมี่ยม เขียนด้วยมือ จัดวางที่ซับซ้อน คณิตศาสตร์)
การตรวจสอบสิทธิ์
ตรวจสอบสิทธิ์ด้วย ตัวแทน API หามันใน หน้าบัญชี) เป็นส่วนหัวของผู้รับ:
Authorization: Bearer YOUR_API_TOKEN
นายก็สามารถผ่านไปได้ ?api_token=… เป็นพารามิเตอร์คำถาม การใช้งานจะถูกวัดจากสมดุลหน้าของบัญชีของคุณ
ส่งเอกสาร
POST /api/v1/ocr/, รูปแบบหลายส่วนที่อัพโหลด
curl -X POST https://pdf.chat/api/v1/ocr/ \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file=@invoice.pdf" \
-F "tier=vlm" \
-F "language=auto"
คืนค่างานกลับมา สำหรับแฟ้มที่มีขนาด ≤5หน้า มันจะถูกส่งกลับมาแล้ว done กับข้อความ; แฟ้มขนาดใหญ่กว่าจะกลับมา pending/processingตรวจสอบสถานะของจุดจบ
{
"uuid": "9f2c1b7e4a...",
"status": "done",
"tier": "vlm",
"language": "auto",
"page_count": 1,
"mean_confidence": 0.98,
"text": "INVOICE\nAcme Corp\nTotal: 215.00 USD",
"markdown": "# INVOICE\n\n**Acme Corp** ...",
"pages": [ { "index": 0, "text": "...", "blocks": [ { "text": "...", "bbox": [x0,y0,x1,y1], "confidence": 0.98 } ] } ]
}
หาผลลัพธ์
GET /api/v1/ocr/<uuid>/, ถามจนกว่า status มันคือ done หรือ failed.
curl https://pdf.chat/api/v1/ocr/9f2c1b7e4a.../ \
-H "Authorization: Bearer YOUR_API_TOKEN"
ดาวน์โหลดรูปแบบ
GET /api/v1/ocr/<uuid>/download/?format=md, ส่งออกผลลัพธ์ format มันเป็นหนึ่งใน txt, md, docx, pdf, csv, json.
curl -L "https://pdf.chat/api/v1/ocr/9f2c1b7e4a.../download/?format=docx" \
-H "Authorization: Bearer YOUR_API_TOKEN" -o result.docx
Chat กับเอกสาร
ถามคำถามเกี่ยวกับงานที่เสร็จสมบูรณ์ คำตอบจะถูกกำหนดโดยข้อความที่ดึงออกมาเท่านั้น และอ้างถึงหน้าต้นฉบับ ต้องการใช้โทเค็นบัญชี ผู้ใช้ ตัวเลือก chat ใช้กับบัญชีผู้ใช้
POST /api/v1/chat/<uuid>/, ส่วนตัว JSON {"message": "your question"}.
curl -X POST https://pdf.chat/api/v1/chat/9f2c1b7e4a.../ \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message": "What is the invoice total and due date?"}'
แสดงผลข้อความของผู้ช่วยพร้อมคำตอบและรายการหน้าที่อ้างถึง:
{"conversation": "a1b2…", "message": {
"role": "assistant",
"content": "The total is $42, due on March 3 (p. 1).",
"citations": [{"page": 1, "cited_text": "The invoice total is $42…", "document_id": "9f2c1b7e4a…"}]
}}
GET /api/v1/chat/<uuid>/history/, เอาข้อมูลการสนทนาทั้งหมดมาให้
ตัวอย่างโค้ด
import requests, time
BASE = "https://pdf.chat/api/v1"
H = {"Authorization": "Bearer YOUR_API_TOKEN"}
# 1. Upload a PDF
with open("contract.pdf", "rb") as f:
job = requests.post(BASE + "/ocr/", headers=H, files={"file": f}).json()
# 2. Wait until it's ready to chat
while job["status"] in ("pending", "processing"):
time.sleep(2)
job = requests.get(f"{BASE}/ocr/{job['uuid']}/", headers=H).json()
# 3. Ask questions — every answer is cited to the page
ans = requests.post(f"{BASE}/chat/{job['uuid']}/", headers=H,
json={"message": "What is the termination notice period?"}).json()
print(ans["message"]["content"])
print(ans["message"]["citations"])
import fs from "fs";
const BASE = "https://pdf.chat/api/v1";
const H = { Authorization: "Bearer YOUR_API_TOKEN" };
// 1. Upload a PDF
const form = new FormData();
form.append("file", new Blob([fs.readFileSync("contract.pdf")]), "contract.pdf");
let job = await (await fetch(`${BASE}/ocr/`, { method: "POST", headers: H, body: form })).json();
// 2. Wait until it's ready to chat
while (["pending", "processing"].includes(job.status)) {
await new Promise(r => setTimeout(r, 2000));
job = await (await fetch(`${BASE}/ocr/${job.uuid}/`, { headers: H })).json();
}
// 3. Ask questions — every answer is cited to the page
const ans = await (await fetch(`${BASE}/chat/${job.uuid}/`, {
method: "POST", headers: { ...H, "Content-Type": "application/json" },
body: JSON.stringify({ message: "What is the termination notice period?" })
})).json();
console.log(ans.message.content, ans.message.citations);
# 1. Upload a PDF
curl -X POST https://pdf.chat/api/v1/ocr/ \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file=@contract.pdf"
# 2. Ask questions (use the uuid from step 1) — answers cited to the page
curl -X POST https://pdf.chat/api/v1/chat/UUID/ \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message": "What is the termination notice period?"}'
พารามิเตอร์
| ช่อง | ประเภท | คำอธิบาย |
|---|---|---|
file | file | จำเป็น รูปภาพหรือ PDF ที่ต้องการประมวลผล |
tier | string | cpu (ปริยาย, เร็ว/ พิมพ์) หรือ vlm (อัจฉริยะระดับพรีเมี่ยม: เขียนด้วยมือ, วางรูป, คณิตศาสตร์) |
language | string | auto ภาษาen, ch, ja, ar,... |
tool | string | ตัวเลือกของเครื่องมือ (เช่น summarize-pdf, ask-pdfที่จะทำการเตรียม chat ไว้ก่อน สำหรับงานนั้น |
ข้อผิดพลาดและขอบเขต
| รหัส | หมายความว่า |
|---|---|
400 | ไม่มีแฟ้ม, ชนิดที่ไม่รองรับ หรือแฟ้มขนาดใหญ่เกินไป |
401 | ไม่มีหรือไม่สามารถใช้ API token ได้ |
402 | หมดหน้า, ถึงจำนวนที่จำกัดของการใช้งานฟรีในวัน/ เดือน หรือไม่มีเครดิต used/cap. |
404 | ไม่พบ UUID ของงาน |
409 | มีการร้องขอการดาวน์โหลดก่อนที่งานจะเสร็จสมบูรณ์ |
ค่าใช้จ่ายในการประมวลผลหน้าเว็บแต่ละหน้า (1/ หน้าเว็บในระดับเร็ว, มากขึ้นในระดับพิเศษ) สำหรับแผนการจ่ายเงิน จะเพิ่มจำนวนหน้าเว็บต่อแฟ้ม และเพิ่มความสำคัญ โปรดดู ค่า.
คำถามที่ถามบ่อย
language=auto เพื่อตรวจจับ หรือส่งรหัสเฉพาะ