← Blog

Claude API PDF Extraction and Analysis: A Developer Guide

2026-11-20 · 5 min read · SubToAPI Team

If you need to pull structured data, summaries, or answers out of PDFs programmatically, the Claude API can read PDF files directly and reason about their content — no separate OCR pipeline required for most documents. You send the PDF as part of the message content, and Claude processes both the text and the visual layout (tables, charts, scanned pages) in a single pass.

This matters because PDF extraction has historically meant stitching together OCR tools, layout parsers, and regex cleanup. Claude's native PDF support collapses that into one API call: upload the file, ask your question or request your schema, and get structured output back. This guide covers how it works, what the limits are, and how to build a reliable extraction pipeline around it.

How Claude Handles PDFs

Claude's document understanding treats each page of a PDF as both text and image. That means it can read:

You don't need to pre-convert pages to images or run OCR first — Claude does this internally. This is a real advantage over text-only extraction pipelines that fail silently on scanned pages.

Sending a PDF in a Request

A typical request includes the PDF as a base64-encoded document block alongside your prompt:

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-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [{
      "role": "user",
      "content": [
        {
          "type": "document",
          "source": {
            "type": "base64",
            "media_type": "application/pdf",
            "data": "BASE64_PDF_DATA"
          }
        },
        {
          "type": "text",
          "text": "Extract the invoice number, total amount, and due date as JSON."
        }
      ]
    }]
  }'

Claude reads the document, interprets the layout, and returns the fields you asked for. For multi-page PDFs, it processes every page within the request, which is useful for contracts, reports, or statements that span dozens of pages.

Practical Extraction Patterns

1. Structured field extraction

For invoices, receipts, or forms, ask for a strict JSON schema in the prompt:

Return only valid JSON with keys: invoice_number, vendor_name, line_items (array), total, currency, due_date.
If a field is missing, use null.

Being explicit about the schema and null handling avoids malformed output you'd otherwise have to patch downstream.

2. Summarization and Q&A over long documents

For contracts or research papers, you can ask Claude to summarize specific sections, flag risky clauses, or answer targeted questions ("What's the termination notice period?"). Because Claude sees the full layout, it can reference page numbers or section headers in its answer, which helps with auditability.

3. Table extraction

Tables embedded in PDFs are often the hardest part of traditional extraction. Ask Claude to return tables as CSV or JSON arrays of rows — it generally preserves column alignment even when the PDF table spans a page break.

4. Batch processing many PDFs

If you're processing a folder of PDFs (e.g., monthly statements), loop over files and send each as a separate request with the same extraction prompt. Keep the prompt identical across the batch so output format stays consistent, and validate each response against your expected schema before writing to your database.

Limits and Things to Watch For

Building This Into a Product

If you're exposing PDF extraction as a feature in your own app rather than a one-off script, you'll run into the usual production concerns: API key management per customer, rate limiting, usage tracking, and billing attribution. This is exactly the layer SubToAPI adds on top of your existing Claude access — issue a scoped sub_live_... key per customer or team, route your PDF extraction requests through it, and get usage metadata (tokens in/out per request) without building that instrumentation yourself.

A basic call through SubToAPI looks like this:

const response = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
    "content-type": "application/json"
  },
  body: JSON.stringify({
    model: "claude-sonnet-4-5",
    max_tokens: 1024,
    messages: [{
      role: "user",
      content: [
        { type: "document", source: { type: "base64", media_type: "application/pdf", data: pdfBase64 } },
        { type: "text", text: "Extract line items as a JSON array." }
      ]
    }]
  })
});

Same request shape as the raw Anthropic API, but with API keys, streaming, and per-key usage tracking handled for you. See the quickstart or the messages reference for the full request format, and pricing for Solo, Team, and Scale plans if you're scaling this across a product or team.

questions

Can Claude extract data from scanned (image-only) PDFs? Yes. Claude processes PDF pages visually as well as textually, so it can read scanned documents without a separate OCR step, though very low-quality scans and handwriting reduce accuracy.

What's the best way to get consistent structured output from PDF extraction? Specify an exact JSON schema in your prompt, including how to handle missing fields, and validate every response against that schema before using it downstream — don't rely on free-text parsing.

Does PDF size affect API cost and limits? Yes. Larger and image-heavy PDFs consume more tokens and may hit page or size limits. Test with representative files first and split very large documents into smaller requests if needed.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →