Claude API PDF Document Processing Guide
Claude's API can read PDFs natively — you don't need a separate OCR pipeline or a PDF-to-text library before sending a document to the model. Claude processes both the text and the visual layout of each page, which means it can answer questions about tables, charts, scanned forms, and multi-column layouts, not just plain text extraction.
This matters because most "PDF processing" problems aren't really about getting text out of a file — they're about getting the right text out, in the right structure, including numbers in tables, labels next to checkboxes, or figures inside charts. This guide covers how PDF input works with the Claude API, how to send documents correctly, and what to watch out for when you move from a prototype to a production pipeline.
How Claude Handles PDF Input
When you send a PDF to Claude, the model receives it as a document content block alongside your text prompt. Internally, Claude processes each page both as text and as an image, which is why it can reason about visual structure — a table's column headers, a form's layout, a chart's axis labels — rather than just a flat stream of extracted characters.
This is different from traditional PDF parsing, where you extract raw text and then hope the layout information wasn't lost. With Claude, you send the file once and ask your question directly: "What was the total revenue in Q3?" or "List every line item in this invoice as JSON."
Sending a PDF to the API
PDFs are sent as base64-encoded data inside a message, using the same messages endpoint you'd use for text or image prompts. Here's a minimal example:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "BASE64_ENCODED_PDF"
}
},
{
"type": "text",
"text": "Extract every line item from this invoice as a JSON array with description, quantity, and price."
}
]
}
]
}'
In JavaScript, the base64 encoding step looks like this:
import fs from "fs";
const pdfData = fs.readFileSync("./invoice.pdf").toString("base64");
const response = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"x-api-key": process.env.ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
},
body: JSON.stringify({
model: "claude-3-5-sonnet-20241022",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{ type: "document", source: { type: "base64", media_type: "application/pdf", data: pdfData } },
{ type: "text", text: "Summarize the key findings in this report in bullet points." },
],
},
],
}),
});
What You Can Extract From PDFs
Because Claude reads both text and layout, PDF processing with the API goes well beyond simple text dumps:
- Structured data extraction — pull line items, totals, dates, and fields from invoices, receipts, or contracts directly into JSON.
- Table understanding — ask questions about specific rows or columns in financial statements or spreadsheets exported to PDF.
- Form parsing — read checkboxes, signatures, and labeled fields from scanned or digitally generated forms.
- Multi-document comparison — send two or more PDFs in the same request and ask Claude to compare clauses across contract versions.
- Chart and figure interpretation — describe or extract approximate values from embedded charts and diagrams.
If you need the output in a predictable shape for downstream systems, pair your extraction prompt with a clear JSON schema description and ask Claude to return only the JSON object, with no surrounding commentary.
Multi-Page and Large Document Considerations
PDFs consume tokens based on their content — more pages and denser text mean more input tokens. A few practical guidelines:
- Keep an eye on total pages per request; very long documents (100+ pages) may need to be split into logical sections (chapters, date ranges) rather than sent as one giant file.
- If you only need specific pages, consider pre-splitting the PDF client-side before upload rather than relying on the model to ignore irrelevant sections.
- For repeated queries against the same document, cache the extracted base64 data on your side rather than re-reading the file from disk on every request.
- Scanned PDFs (image-only, no embedded text layer) work fine since Claude reads the visual content directly, but very low-resolution scans can reduce accuracy on small text.
Common Use Cases
PDF processing with the Claude API shows up in a lot of production systems:
- Invoice and receipt automation for finance teams extracting structured data into accounting software.
- Contract review tools that flag non-standard clauses across legal documents.
- Research assistants that answer questions across academic papers or technical specs.
- Compliance and audit tooling that checks forms against required fields.
- Customer support systems that read uploaded PDFs (insurance policies, manuals) to answer user questions.
Using SubToAPI for PDF Document Pipelines
If you're building a product on top of Claude's document capabilities, you still need standard API infrastructure: application-scoped keys, usage metadata per request, streaming for long extraction jobs, and team access control — none of which Claude's raw API gives you by itself.
SubToAPI turns your existing Claude access into an HTTPS API with sub_live_... keys you can issue per application or per customer, so a PDF-processing feature in your product doesn't need to share a single Anthropic key across every environment. Requests to document endpoints work the same way as any other Claude call — see the messages docs for the request format and streaming docs if you're extracting from long documents and want partial results as they're generated. Usage and cost per key are visible in the dashboard, which is useful when you're billing PDF processing as a feature to different teams or customers.
Setup takes a few minutes — check the quickstart, compare plans, or start a free trial if you want to try it against a real document pipeline.
Best Practices for PDF Document Processing
- Be explicit about output format in your prompt — ask for JSON with a defined schema if you're parsing the result programmatically.
- Validate extracted numbers against expected ranges or totals, especially for financial documents, before trusting them downstream.
- Use the tools documentation if you want Claude to call a function with the extracted structured data rather than returning free text.
- Test with real-world messy PDFs (skewed scans, multi-column layouts, handwritten annotations) early — clean sample PDFs rarely represent production input.
- Log raw model output alongside parsed results so you can debug extraction errors without re-running the request.
FAQ
Does Claude need a text layer in the PDF, or can it read scanned documents? Claude reads PDFs as both text and images, so scanned or image-only PDFs work without a separate OCR step. Very low-resolution scans may reduce accuracy on small text.
What's the best way to get structured JSON out of a PDF with Claude? Describe the exact JSON schema you want in your prompt and instruct Claude to return only the JSON object. Pairing this with the tools/function-calling feature gives even more reliable structured output.
Can I send multiple PDFs in one request? Yes — you can include multiple document content blocks in a single message, which is useful for comparing contract versions or cross-referencing data across related files.