PDF. chat API
Una petició HTTP converteix una imatge o PDF en text net, Markdown, taules i JSON, en 100 llengües+. Medorat per pàgina, no sorpreses.
Resum
The PDF.chat API is a small REST interface. First you POST un document per a agafar- lo i tornar- lo a una feina amb el text del document i una crisi per pàgina (text, caixes lligades, confiança). POST Preguntes contra aquesta feina i respostes afeïdes en el document, cada citant la pàgina que prové. Tasques de 5 pàgines o menys retornades inserides; les feines més grans tornen immediatament amb una pending estat que l'enquesta fins a done.
- URL base:
https://pdf.chat - Documents a: PDF, més paraules, PowerPoint, text i imatges (PNG, JPG, WBP, GIF, BMP, TIFF)
- Chat out: Respostes amb citacions de pàgina; transcripcions mitjançant el punt final de l' historial
- Text processat:
txt,md,docx,pdf,csv,json - S' estan llegint els motors:
cpu(més ràpid, documents impresos) ivlm(promiA, lletra, disposició complexa, matemàtiques)
Autenticació
Autenticat amb vós testimoni API (t'ho he trobat a sobre teu. pàgina de compte) com a capçalera de l'ós:
Authorization: Bearer YOUR_API_TOKEN
També pots passar. ?api_token=… com a paràmetre de consulta. L' ús s' ha mesurat contra el balanç de la pàgina del compte.
Envia un document
POST /api/v1/ocr/, Pujada de tipus multipart.
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"
Retorna la tasca. Per a fitxers de pàgina Returns5 ja està done amb el text; els fitxers més grans tornen pending/processing, enquesta el punt d' acabament.
{
"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 } ] } ]
}
Obtén un resultat
GET /api/v1/ocr/<uuid>/, electoral fins a status és done o failed.
curl https://pdf.chat/api/v1/ocr/9f2c1b7e4a.../ \
-H "Authorization: Bearer YOUR_API_TOKEN"
Descarrega un format
GET /api/v1/ocr/<uuid>/download/?format=md, Exporta el resultat. format és un dels 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
Xateu amb un document
Pregunta sobre una feina acabada. Les respostes només estan castigadas en el text extret i cite la pàgina font. Requereix un testimoni de compte, la característica de xat està en compte-gate.
POST /api/v1/chat/<uuid>/, Cos 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?"}'
Retorna el missatge assistent amb la resposta i una llista de pàgines citades:
{"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/, Recupera la transcripció total de conversa per a una feina.
Exemples de codi
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?"}'
Paràmetres
| Camp | Tipus | Descripció |
|---|---|---|
file | file | Es requereix. La imatge o PDF a processar. |
tier | string | cpu (per omissió, ràpid/ imprimeixed) o vlm (promiA: lletra, disposició, matemàtiques). |
language | string | auto (per omissió) o un codi d' idioma (en, ch, ja, ar..). |
tool | string | Plantilla d' eina opcional (p. ex. summarize-pdf, ask-pdf) to pre-frame the chat for that task. |
Errors i límits
| Codi | Significat |
|---|---|
400 | No hi ha cap fitxer, tipus no implementat, o fitxer massa gran. |
401 | Falta o no és vàlida la fitxa API. |
402 | Sense pàgines, s' abasta cada dia/ mesos, o sense crèdits. El cos inclou used/cap. |
404 | No s' ha trobat el treball UUID. |
409 | La descàrrega ha sol· licitat abans que acabi la feina. |
Cada pàgina processada costa crèdits (1/page en el empat ràpid, més en el valor de la barra lateral). Els plans que s' aixequen per fitxer de pàgines i afegeix prioritat. Mireu fixació de preus.
Preguntes més freqüents
language=auto per a detectar o passar un codi específic.