How to Use the PDF.ai Chat API
Publish date
Oct 1, 2026
AI summary
The page explains how to use PDF.ai’s v1 Chat API: upload a PDF to obtain a docId, then POST /v1/chat with that docId and a question to receive an answer (and optional references), optionally saving chat history; it details required headers, model choices, credit costs for uploads and messages, and provides code examples, usage guidelines, and links to related API endpoints and resources.
Language
People look up a Chat API when they already upload PDFs into their product and need a question → answer loop in code — with optional chat history — not a browser-only chat, and not the newer v2 Ask path that starts from Parse.
This page is the upload → chat with one PDF path on the PDF.ai API v1 Chat endpoint. It does not replace the API Hub (keys and plan live there). It does not re-rank the head term pdf api. It is not the v2 Ask endpoint (
POST /v2/ask), which requires a prior Parse docId. For the first-request path on v2 Parse, see How to Get Started with the PDF.ai API. For free-form answers on already-parsed v2 docs, see How to Use the PDF.ai Ask API. For chat without code, see How to Chat with a PDF.What Chat is for
After a clean Chat call on PDF.ai API v1, three things should be true:
- You already uploaded the PDF (URL or file) and kept its
docId
- You sent that
docIdplus amessage(question) with yourX-API-Key
- The response includes an answer
contentstring and optionalreferences(page and line ranges)
Docs: Chat with PDF, Upload PDF.
Practical rule: Chat (v1) answers a free-form question against one uploadeddocId. Ask (v2) answers against one or more parseddocIds. Use Chat when your pipeline already uses v1 upload + chat history; use Ask when you are on the v2 Parse → Ask path.
Browser chat vs Chat API vs Ask API
Path | Best when | What you get |
Web chat UI | One file, no code | Answers in the browser |
API POST /v1/chat | v1 upload library, optional save_chat history | JSON ( content · references) with an X-API-Key |
API POST /v2/ask | v2 Parse first, multi- docId prompts |
Credits before you scale questions
From the live Chat with PDF and API limits docs:
- Upload: 2 credits per file upload (Dedicated API plan credit model on API limits)
- Chat message (with GPT-4 path): gpt-4o → 2 credits per message; gpt-4-turbo (default when using that model field) → 4 credits per message
- gpt-3.5-turbo / gpt-4o-mini messages are listed on API limits as 1 credit per message when that model path applies
API plan examples on credit usage (key + plan live on the developer hub):
- Free: $0/month for 200 credits/month, no credit card required
- Paid examples: $49 / 3,000, $99 / 10,000, $249 / 30,000, $599 / 100,000 credits per month
Generate the key and manage the plan on https://pdf.ai/developer. The docs say the key is shown only once when generated.
Practical rule: count upload credits once per file, then message credits per Chat call. Turning on a heavier model raises the per-message cost; it does not change the upload fee.
How to call Chat
1. Have an API key
Open https://pdf.ai/developer, generate a key, store it as a secret. Send it as the
X-API-Key header on every call.2. Upload first and keep the docId
Chat requires a
docId from a prior upload. From Upload PDF:- URL upload:
POST https://pdf.ai/api/v1/upload/urlwith requiredurl(timeout 300 seconds; use this path when the file is larger than the file-upload limit)
- File upload:
POST https://pdf.ai/api/v1/upload/filewith requiredfile(FormData); file size limit 4.5 MB; timeout 300 seconds
Optional upload fields from the docs:
isPrivate, ocr (make scanned text searchable), tags (array of strings).A successful upload returns a
docId. Keep it for Chat (and for Chat history if you save turns).3. POST docId + message
Endpoint from the docs:
POST https://pdf.ai/api/v1/chatRequired (from Chat with PDF):
docId— document ID from upload
message— the question or instruction
Optional:
save_chat— save history (viewable under PDF.ai documents); the oldchatIdfield is deprecated — usesave_chatonly
use_gpt4— use a GPT-4 model path
model—"gpt-4o"or"gpt-4-turbo"(default when choosing that family)
language— response language (e.g."french")
sys_prompt— custom system prompt
Example shape (Python), matching the docs parameters:
import requests
url = "https://pdf.ai/api/v1/chat"
headers = {
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"docId": "your-document-id",
"message": "What is the main topic of this document?",
"save_chat": True,
"model": "gpt-4o"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())A successful response includes
content (the answer) and may include references with pageNumber, fromLine, and toLine.4. Optional: history and multi-doc chat
- History: If you set
save_chatto true, retrieve turns withPOST https://pdf.ai/api/v1/historyand the samedocId(Chat history). To remove saved chat with the document, use the delete path for that PDF (see How to Use the PDF.ai Delete API for v2 cleanup; v1 documents use the v1 delete path the docs describe).
- Chat across uploads:
POST https://pdf.ai/api/v1/chat-allasks across your uploaded library (optionaltag,topMatches; default top matches 10) — see Chat with all PDFs.
5. Check the output before you trust it
- Confirm
contentanswers the question you asked
- Spot-check claims against the source PDF using any
referencespage/line ranges
- If you get
Invalid API key/No API key present, fix the header before you change the message
- If Chat rejects a
docId, upload (or re-upload) that file first and retry with the returned id
Practical rule: a fluentcontentstring is still a model reply. Read it against the source pages before you show it to end users as fact.
When Chat is the wrong tool
- You only need one chat answer in a browser. Use How to Chat with a PDF. No API key required for that job.
- You are already on v2 Parse and want multi-doc prompts. Prefer
POST /v2/ask(How to Use the PDF.ai Ask API).
- You need named fields / tables as JSON. Use
POST https://pdf.ai/api/v2/extractwith a schema (How to Use the PDF.ai Extract API).
- You only need searchable markdown / contents. Prefer v2 Parse (How to Use the PDF.ai Parse API).
- You wanted a generic “pdf api” category hub. Stay on https://pdf.ai/developer. This page is the Chat how-to, not a replacement hub.
A short action plan
- Open https://pdf.ai/developer, create a key, store it once.
- Upload the PDF (
/v1/upload/urlor/v1/upload/file) and keep thedocId.
- Check message credits for your chosen
modelon Chat with PDF / API limits.
POST https://pdf.ai/api/v1/chatwithdocId+message(setsave_chatif you need history), then verifycontentagainst the source PDF before you wire production.
Sibling guides: How to Get Started with the PDF.ai API, How to Use the PDF.ai Ask API, How to Use the PDF.ai Parse API, How to Understand PDF.ai API Credit Usage, How to Use the PDF.ai Delete API, How to Chat with a PDF.
If you want the rest of the PDF workflow after the answer is clean, start at PDF.ai. Use the Chat API when the next step is a v1 upload + Q&A loop in your product, not a single upload box.