PDF.chat API
Upload a PDF and chat with it from your own app — ask questions and get answers cited to the page, in 100+ languages. Metered per page, no surprises.
Ringkasan
The PDF.chat API is a small REST interface. First you POST dokumen untuk menelan dan mendapatkan kembali pekerjaan dengan teks dokumen dan per-halaman rincian (teks, kotak batas, keyakinan). Kemudian Anda POST pertanyaan terhadap pekerjaan itu dan mendapatkan jawaban berdasarkan dokumen, masing-masing mengutip halaman itu berasal dari. pekerjaan dari 5 halaman atau lebih sedikit kembali dalam baris; pekerjaan yang lebih besar kembali segera dengan pending status yang anda geluti sampai done.
- URL Dasar:
https://pdf.chat - Dokumen masuk: PDF, ditambah Word, PowerPoint, teks, dan gambar (PNG, JPG, WEBP, GIF, BMP, TIFF)
- Chat out: jawaban dengan halaman kutipan; transkrip melalui titik akhir sejarah
- Teks yang diproses keluar:
txt,md,docx,pdf,csv,json - Reading mesin:
cpu(cepat, dicetak docs) danvlm(premium AI, tulisan tangan, tata letak kompleks, matematika)
Otentikasi
Lakukan otentikasi dengan Token API (Temukan di bajumu) halaman akun) Sebagai kepala Bearer:
Authorization: Bearer YOUR_API_TOKEN
Kau juga bisa lulus. ?api_token=… sebagai parameter query. Penggunaan diukur dengan keseimbangan halaman akun anda.
Ajukan dokumen
POST /api/v1/ocr/, multipart form 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"
Mengembalikan pekerjaan. Untuk berkas halaman 5 itu sudah done dengan teks; berkas yang lebih besar kembali pending/processing, jajak pendapat titik akhir status.
{
"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 } ] } ]
}
Dapatkan hasilnya
GET /api/v1/ocr/<uuid>/, polling sampai status adalah done atau failed.
curl https://pdf.chat/api/v1/ocr/9f2c1b7e4a.../ \
-H "Authorization: Bearer YOUR_API_TOKEN"
Unduh suatu format
GET /api/v1/ocr/<uuid>/download/?format=md, ekspor hasilnya. format adalah salah satu 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
Mengobrol dengan dokumen
Ajukan pertanyaan tentang pekerjaan yang selesai. Jawaban didasarkan hanya pada teks yang diekstrak dan mengutip halaman sumber. Perlu akun token, fitur percakapan akun-ditegorikan.
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?"}'
Mengembalikan pesan asisten dengan jawabannya dan daftar halaman-halaman yang 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/, mengambil transkrip percakapan lengkap untuk pekerjaan.
Contoh 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?"}'
Parameter
| Ruas | Tipe | Deskripsi |
|---|---|---|
file | file | Diperlukan. Gambar atau PDF untuk diproses. |
tier | string | cpu (bawaan, cepat/dicetak) atau vlm (premium AI: tulisan tangan, tata letak, matematika). |
language | string | auto (bawaan) atau kode bahasa (en, ch, ja, ar,...). |
tool | string | Siput alat opsional (misalnya. summarize-pdf, ask-pdf) to pre-frame the chat for that task. |
Galat & batas
| Kode | Artinya |
|---|---|
400 | Tak ada berkas, tipe yang tak didukung, atau berkas terlalu besar. |
401 | Token API yang hilang atau tak valid. |
402 | Dari halaman, batas bebas per hari/bulan tercapai, atau tanpa kredit. Tubuh termasuk used/cap. |
404 | UUID Job tak ditemukan. |
409 | Unduhan permintaan sebelum pekerjaan selesai. |
Setiap halaman diproses biaya kredit (1/halaman pada tingkat cepat, lebih pada premium). Rencana dibayar meningkatkan tutup halaman per-berkas dan menambah prioritas. Lihat. Harga.
Sering kali mengajukan pertanyaan
language=auto untuk mendeteksi, atau lulus kode tertentu.