PDF extraction API for AI agents
How to give an AI agent a PDF extraction API: what it is, when agents need one, a working curl example, cost controls, and how it compares to OCR-plus-LLM pipelines.
PDF extraction API for AI agents
A PDF extraction API for AI agents is a tool endpoint that converts a PDF into structured JSON or markdown an agent can act on — with page references, table structure, and predictable cost per call. The main qualification: most agents fail on PDFs not because the model is weak, but because naive pipelines lose reading order, break tables, and cannot cite where a value came from. This post explains when agents need a dedicated extraction API, how to wire one up, and what it costs.
Why AI agents need a dedicated PDF extraction API
Agents break on PDFs for three reasons that a plain OCR-plus-LLM pipeline does not solve:
- Reading order. Multi-column layouts, headers, and footnotes get flattened into a text stream, so the LLM reads columns out of sequence.
- Tables. OCR output of a table is a wall of text; merged cells and nested rows disappear. The agent cannot answer "what was the Q3 total" reliably.
- Grounding. Without page numbers or coordinates, the agent cannot verify a claim, and downstream users cannot audit it.
A dedicated extraction API solves this by returning structured output — fields, tables, and page citations — instead of raw text. The agent calls it like any other tool, gets JSON back, and reasons over verified data rather than reconstructed text.
How to extract a PDF with DeepAPI in one call
DeepAPI exposes PDF extraction as a single endpoint with one API key — no OAuth setup for the public API. Here is a working curl example:
curl -X POST https://api.deepapi.co/v1/pdf/extract \
-H "Authorization: Bearer $DEEPAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/invoice.pdf",
"output_format": "markdown",
"maxCostUsd": 0.10
}'
The response returns extracted text and tables with page references. Two properties matter for agents:
maxCostUsdcaps what a single request can spend, so a runaway agent loop cannot drain a budget.- Failed calls are free. If extraction fails on a malformed or unreadable PDF, you pay nothing.
Full parameter reference is in the DeepAPI PDF extraction docs.
What an agent can extract
A PDF extraction API for AI agents should return, at minimum:
- Text with reading order — clean markdown suitable for RAG chunking.
- Tables — rows and columns preserved as JSON, including merged cells.
- Key-value pairs — form fields, invoice headers, contract clauses.
- Page citations — so the agent can say "page 4, line 12" instead of guessing.
Scanned PDFs need OCR or a vision model on top of layout parsing. Accuracy on scans varies heavily with document quality, so test on your own files before trusting any provider's headline number — we do not publish a single accuracy figure because none applies universally.
PDF extraction API vs. alternatives
| Approach | What it returns | Agent fit | Cost control |
|---|---|---|---|
| DeepAPI extraction endpoint | Structured JSON / markdown with page refs | One API key, tool-call ready, maxCostUsd per request, failed calls free | Per-request cap |
| Raw OCR + LLM | Flattened text | Loses tables and reading order; no citations | Two bills, no cap |
| LLM file upload | Model's internal parse | Convenient, but no schema guarantee or page grounding | Token-priced, unpredictable on long PDFs |
| Enterprise document platform | Structured data with audit trails | Strong accuracy, but sales-gated setup and per-page contracts | Opaque until you talk to sales |
DeepAPI is the best fit when the consumer is an autonomous agent: one key, no OAuth ceremony, per-call cost caps, and free failures mean you can let an agent call it unsupervised. Enterprise platforms win when you need human-in-the-loop review UIs and signed contracts; raw OCR wins only for trivially simple, text-native PDFs.
Cost and limits
We will not quote an industry price per page because published numbers are not comparable across vendors (per-page, per-call, and per-token pricing all differ). What we can state plainly:
- DeepAPI bills per request, and every request accepts
maxCostUsd. - Failed calls are free — you never pay for a PDF the API could not process.
- One API key covers all DeepAPI endpoints, so an agent doing PDF extraction plus web search or browser automation needs no extra auth setup.
Known limits: very large PDFs and heavy scans cost more per request, which is exactly why the per-request cap exists. Set maxCostUsd to what one extraction is worth to you and the agent cannot exceed it.
How PDF extraction fits an agent's tool stack
Extraction rarely runs alone. Typical agent workflows that need it:
- Research agents pull PDFs found via deep research or web search, extract them, and cite pages.
- Data agents extract tables from reports and cross-check them against GitHub repos or scraped pages.
- Ops agents extract invoices and then send email with the results.
In each case the pattern is the same: the agent calls extraction as one tool among several, under one key and one cost cap.
Get started
Sign up at deepapi.co, grab your API key, and run the curl example above on your own PDF. Failed calls are free, so testing costs you nothing until it works.
FAQ
- What is a PDF extraction API for AI agents?
- A PDF extraction API for AI agents is a tool endpoint an agent can call to turn a PDF into structured JSON or markdown, so the agent can read invoices, contracts, and reports without a human preprocessing step.
- Does DeepAPI charge for failed extraction calls?
- No. Failed calls are free on DeepAPI, and every request can set a maxCostUsd cap so an agent cannot overspend on a single extraction.
- Do I need OAuth to use the DeepAPI PDF extraction endpoint?
- No. The public API uses one API key with no OAuth setup, so an agent can call the endpoint with a single Authorization header.
- Can an agent extract tables from scanned PDFs?
- Yes, if the extraction endpoint handles scanned pages with OCR or a vision model. Test on your own scanned documents first; scanned quality varies and no accuracy number applies to every file.
- How much does PDF extraction cost per agent run?
- Costs vary by provider and page count, and we do not publish a single industry number. With DeepAPI you control spend per request with maxCostUsd, and failed calls cost nothing.
- What output format should a PDF extraction API return for agents?
- Structured JSON with page references, or clean markdown for RAG pipelines. Both let the agent cite where each value came from instead of trusting raw text.
- How is this different from just sending the PDF to an LLM?
- Sending a raw PDF to an LLM loses reading order, table structure, and page citations on complex layouts. A dedicated extraction API returns grounded, structured output the agent can verify.
Originally published at https://deepapi.co/blog/pdf-extraction-api-for-ai-agents.