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 docId plus a message (question) with your X-API-Key
  • The response includes an answer content string and optional references (page and line ranges)
Practical rule: Chat (v1) answers a free-form question against one uploaded docId. Ask (v2) answers against one or more parsed docIds. 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
JSON (success · answer); see Ask API

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/url with required url (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/file with required file (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/chat
Required (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 old chatId field is deprecated — use save_chat only
  • 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_chat to true, retrieve turns with POST https://pdf.ai/api/v1/history and the same docId (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-all asks across your uploaded library (optional tag, topMatches; default top matches 10) — see Chat with all PDFs.

5. Check the output before you trust it

  • Confirm content answers the question you asked
  • Spot-check claims against the source PDF using any references page/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 fluent content string 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 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

  1. Open https://pdf.ai/developer, create a key, store it once.
  1. Upload the PDF (/v1/upload/url or /v1/upload/file) and keep the docId.
  1. Check message credits for your chosen model on Chat with PDF / API limits.
  1. POST https://pdf.ai/api/v1/chat with docId + message (set save_chat if you need history), then verify content against the source PDF before you wire production.
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.