API PDF.chat
Llwythwch i fyny PDF a chat gyda hi o'ch rhaglen eich hun - gofyn cwestiynau a chael atebion wedi'u dyfynnu i'r dudalen, mewn 100+ iaith. Mesuredig ar bob tudalen, dim syndod.
Crynodeb
Rhyngwyneb REST bach yw'r API PDF.chat. Yn gyntaf, chi POST dogfen i'w chymryd hi a chael swydd yn ôl gyda testun y ddogfen a phrosiect y dudalen (testun, blychau terfynu, ymddiriedaeth). Wedyn gallwch POST gofyn cwestiynau yn erbyn y swydd hon a chael atebion wedi'u seilio ar y ddogfen, pob un yn dyfynnu'r dudalen y daeth ohono. Mae swyddi o 5 tudalen neu lai yn dychwelyd yn llinell; mae swyddi mwy yn dychwelyd yn syth gyda pending statws y byddwch yn pleidleisio hyd done.
- URL sylfaenol:
https://pdf.chat - Dogfennau mewn: PDF, yn ogystal â Word, PowerPoint, testun a delweddau (PNG, JPG, WEBP, GIF, BMP, TIFF)
- Chat allan: atebion gyda dyfyniadau tudalen; trosysgrifau drwy'r pwynt diwedd hanes
- Testun wedi' i brosesu allan:
txt,md,docx,pdf,csv,json - Peiriannau darllen:
cpu(dolenni cyflym, argraffedig) avlm(AI premiwm, ysgrifennu â llaw, cynllun cymhleth, mathemateg)
Dilysiant
Dilysu gyda'ch cyfrinair Tocyn API (canfod ar eich cyfrifiadur) tudalen cyfrif) fel pennawd Bearer:
Authorization: Bearer YOUR_API_TOKEN
Gallwch hefyd basio ?api_token=… fel paramedr ymholiad. Mae'r defnydd yn cael ei fesur yn erbyn balans tudalen eich cyfrif.
Anfon dogfen
POST /api/v1/ocr/, Llwytho i fyny ffurflen aml- ran.
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"
Dychwelyd y swydd. Am ffeiliau ≤5 tudalen mae' n barod done gyda' r testun; mae ffeiliau mwy yn dychwelyd pending/processing, pleidleisio' r pwynt diwedd statws.
{
"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 } ] } ]
}
Cyrchu canlyniad
GET /api/v1/ocr/<uuid>/, chwiliad tan status yw done neu failed.
curl https://pdf.chat/api/v1/ocr/9f2c1b7e4a.../ \
-H "Authorization: Bearer YOUR_API_TOKEN"
Lawrlwytho fformat
GET /api/v1/ocr/<uuid>/download/?format=md, allforio' r canlyniad. format yw un o 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 gyda dogfen
Gofyn cwestiynau am waith wedi' i gwblhau. Mae atebion yn seiliedig ar y testun echdynedig yn unig ac yn dyfynnu' r dudalen ffynhonnell. Mae angen tocyn cyfrif, mae' r nodwedd chat yn cael ei rwystro gan y cyfrif.
POST /api/v1/chat/<uuid>/, Corff 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?"}'
Dychwelyd y neges cynorthwyydd gyda' i ateb a rhestr o dudalennau wedi' u dyfynnu:
{"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/, nôl y traethawd cyfathrebu llawn ar gyfer swydd.
Enghreifftiau o' r Côd
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?"}'
Paramedrau
| Maes | Math | Disgrifiad |
|---|---|---|
file | file | Angenrheidiol. Y ddelwedd neu'r PDF i'w brosesu. |
tier | string | cpu (rhagosodedig, cyflym/argraffedig) neu vlm (AI premiwm: ysgrifennu â llaw, cynllun, mathemateg). |
language | string | auto (rhagosodedig) neu god iaith (en, ch, ja, ar,...) |
tool | string | Slug offer dewisol (e.e. summarize-pdf, ask-pdf) i gyn-fframio'r chat ar gyfer y dasg hon. |
Gwall:
| Cod | Pwysau |
|---|---|
400 | Dim ffeil, math heb ei gynnal, neu ffeil rhy fawr. |
401 | Tocyn API ar goll neu annilys. |
402 | Allan o dudalennau, terfyn rhydd diwrnod/mis wedi ei gyrraedd, neu dim credydau. Mae'r corff yn cynnwys used/cap. |
404 | Methu canfod UUID y swydd. |
409 | Gofynnwyd am lawrlwythiad cyn gorffen y dasg. |
Mae pob tudalen a weithredir yn costio credydau (1/tudalen ar lefel gyflym, mwy ar premiwm). Mae cynlluniau talu yn codi capiau tudalen fesul ffeil ac yn ychwanegu blaenoriaeth. Gweler prisio.
Cwestiynau a ofynnir yn aml
language=auto i ganfod, neu drosglwyddo cod penodol.