PDF.chat API
上传一个PDF和chat, 并自用自用应用程序中调出 —— 以100+ 语言提问并获得页面引用的答案。 以每页处理, 没有任何惊喜 。
概览
PDF.chat API是一个小型的REST接口。 POST 文档中要吸收并恢复文件文本和每页的明细(文本、框框、信任)的工作。然后是您。 POST 这份工作遇到的问题,并获得基于文件的答案,每个文件引用文件的页面。 5页或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(A类保险费、笔迹、复杂布局、数学)
验证
与您的 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 带文档
询问已完成的工作。 答案仅以摘录文本为基础并引用源页。 需要账户标记, 聊天功能将被账户标记 。
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 (A类保险费:笔迹、布局、数学) |
language | string | auto 或语言代码(en, ch, ja, ar..))) |
tool | string | 选用工具弹片(例如: summarize-pdf, ask-pdf)为这项任务预先确定chat个。 |
错误和限制
| 守则法典 | 含义 意思 意思 |
|---|---|
400 | 没有文件、 不支持的类型或文件太大 。 |
401 | 遗失或无效的 API 标牌 。 |
402 | 包括: 网页外、每日/每月自由限制或无分分数,或每日/每月免费限制,或无分分数。 used/cap. |
404 | 找不到任务 UUID 。 |
409 | 任务完成前请求下载 。 |
每页处理成本抵免(快速级的1页,溢价增加1页),支付计划提高每页的上限并增加优先级。 定价.
经常问到的问题
language=auto 来检测或传递特定的代码。