PDF.chat API
Unggah PDF sareng chat sareng éta tina aplikasi anjeun nyalira - naroskeun patarosan sareng kéngingkeun jawaban anu dikutip kana halaman, dina 100 + basa. Diukur per halaman, henteu aya anu ngaherankeun.
Gambaran Umum
The PDF.chat API iku antarmuka REST cilik. Kapisan sampeyan POST Dokumen kanggo ngethok lan nampa maneh tugas karo teks dokumen lan panyebaran saben-saben kaca (teks, kotak wates, kepercayaan). Sawise iku sampeyan bisa POST pitakonan marang kerja iku lan njaluk jawaban didhasarake ing dokumen, saben citing kaca iku teka saka. Jobs saka 5 kaca utawa kurang bali inline; jobs luwih gedhe bali langsung karo pending status that you poll until done.
- URL Dasar:
https://pdf.chat - Dokumen ing: PDF, plus Word, PowerPoint, teks, lan gambar (PNG, JPG, WEBP, GIF, BMP, TIFF)
- Chat metu: jawaban karo citra kaca; transkripsi liwat titik pungkasan sejarah
- Teks diproses:
txt,md,docx,pdf,csv,json - Ngetik
cpu(dokumèn cetak cepet) lanvlm(premium AI, tulisan tangan, tata letak rumit, matematika)
Autentikasi
Autentikasi karo akun sampeyan Token API (goleki ing page) minangka header Bearer:
Authorization: Bearer YOUR_API_TOKEN
Sampeyan uga bisa ngetutake ?api_token=… salaku parameter panalungtikan. Panggunana diukur ngalawan saldo halaman akun anjeun.
Kirim dokumen
POST /api/v1/ocr/, multipart formulir upload.
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"
Kembalikan tugas. Kanggo file ≤5- halaman wis ana done karo teks; file sing luwih gedhe bakal teka maneh pending/processing, poll the status endpoint.
{
"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 } ] } ]
}
Ngambil asil
GET /api/v1/ocr/<uuid>/, poll until status iku done utawa failed.
curl https://pdf.chat/api/v1/ocr/9f2c1b7e4a.../ \
-H "Authorization: Bearer YOUR_API_TOKEN"
Muat turun format
GET /api/v1/ocr/<uuid>/download/?format=md, Eksport hasil. format salah siji saka 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 karo dokumen
Nyaetakeun patarosan ngeunaan tugas anu réngsé. Jawabanna ngan ukur didasarkeun kana teks anu dieksekusi sarta nyalin halaman sumber. Peryogikeun token akun, fitur chat dijaga ku akun.
POST /api/v1/chat/<uuid>/, Tubuh 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?"}'
Kembalikan pesan asisten kanthi jawaban lan dhaptar kaca sing dikutip:
{"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/, nelusuri transkripsi konvertasi lengkap kanggo tugas.
Conto kode
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?"}'
Параметри
| Lapangan | Type | Gambaran |
|---|---|---|
file | file | Diperlukan. Gambar utawa PDF kanggo diproses. |
tier | string | cpu (piawai, cepet/dicetak) utawa vlm (premium AI: tulisan tangan, layout, matematika). |
language | string | auto (piranti lunak) utawa kode basa (en, ch, ja, ar,...). |
tool | string | Kajaba iku, ana uga wangun-wangun dhasar (e.g. summarize-pdf, ask-pdfchat) kanggo preframe chat kanggo tugas iki. |
Kesalahan lan watesan
| Kode | Makna |
|---|---|
400 | Ora ana file, jinis ora didhukung, utawa file akèh banget. |
401 | Token API kang ilang utawa ora sah. |
402 | Luwih saka kaca, watesan gratis saben dina/wulan wis tekan, utawa ora ana kredit. Tubuh kalebu used/cap. |
404 | UUID tugas ora ditemokake. |
409 | Muter- unduh dibutuhake sadurunge tugas rampung. |
Saben kaca sing diproses regane kredit (1/kaca ing tingkat cepet, luwih ing premium). Rencana sing dibayar nambahi watesan kaca saben file lan nambah prioritas. Lihat harga.
Takon-takon kang kerep diajukake
language=auto kanggo ndeteksi, utawa nyelehake kode tartamtu.