MICROPDF / DEVELOPER GUIDE
A PDF in.
A useful response out.
MicroPDF extracts native text and printed English scans into Markdown and page-organized JSON. Send a PDF with an x402-enabled client and receive extracted pages directly, or explicitly choose an asynchronous job.
eip155:84532) and test USDC. Real-money payments are not
offered in this release. Extraction accuracy varies by document.
Base URL: https://api.micropdf.dev
Download the OpenAPI specification
·
Check current capabilities and limits
Extract in one call
Choose x402 with a test wallet or an operator-provisioned API key. The snippet below illustrates the request; the runnable setup includes dependencies, wallet policy and a downloadable client.
Try the sample PDF, actual JSON output and Markdown output before sending your own file.
POST /v1/extract accepts a PDF file or a public HTTPS
URL. An x402-enabled client handles the payment challenge and
retries automatically. The default synchronous mode returns the
extracted pages directly.
// paidFetch is fetch wrapped with your x402 wallet and spending policy.
// Generate and save a secret UUIDv4 key once per extraction.
const form = new FormData();
form.set("file", pdfBlob, "report.pdf");
const response = await paidFetch(
"https://api.micropdf.dev/v1/extract",
{ method: "POST", body: form,
headers: { "Idempotency-Key": savedKey } }
);
const result = await response.json();
Complete TypeScript example with wallet setup and a spending cap →
To inspect the unpaid challenge with curl:
# Generate once; keep this secret and reuse it on retries.
export IDEMPOTENCY_KEY="$(node -e 'console.log(crypto.randomUUID())')"
curl -i 'https://api.micropdf.dev/v1/extract?format=markdown' \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-F 'file=@report.pdf'
Plain curl receives 402 until you send a valid
PAYMENT-SIGNATURE. Repeat the same file, query options
and key on the paid retry.
| Mode | Success | Limits |
|---|---|---|
sync (default) |
200 with results |
5 MB, 10 selected pages, up to 3 OCR pages |
async |
202 with a job and links |
20 MB, 50 pages |
Set query options mode=async,
format=markdown, ocr=never, or
pages=1,3 as needed. JSON output and automatic English
OCR are the defaults. For a URL, send JSON
{"url":"https://example.com/report.pdf"} instead of
multipart. A URL retry reuses the original downloaded PDF.
Sync waits up to 25 seconds after payment, in addition to upload,
inspection and settlement time. It never silently switches to
202. 503 SYNC_BUSY rejects busy capacity
before settlement. 409 SYNC_TIMEOUT means the job
continues: retry the exact request with the same key, or poll
operation.statusUrl with the returned
operation.token as a Bearer token. Once succeeded,
fetch operation.resultUrl. Do not start another paid
operation.
JSON sync results include an operation object. Async
responses return that object directly. Recovery details also appear
in errors once the operation is created. Headers
Location, Operation-Id and
Document-Token provide recovery information for
Markdown responses. Keep both the random key and token secret; they
grant access to the document. Content expires 24 hours after upload.
Do not retry expired operations.
Extract with an API key
API keys are provisioned by the operator; there is no self-service
checkout or public signup yet.
Request access and page credits before using
this flow. Keys begin with mp_live_; that prefix does
not indicate a mainnet wallet.
Send Authorization: Bearer on every request, including
upload, quotes, status, results and deletion. Do not use
X-API-Key or combine an account key with
PAYMENT-SIGNATURE. Account-owned documents do not
return an anonymous document token.
# Set MICROPDF_API_KEY securely; do not commit it to source control.
curl --fail-with-body 'https://api.micropdf.dev/v1/extract?format=markdown' \
-H "Authorization: Bearer $MICROPDF_API_KEY" \
-H 'Idempotency-Key: report-example-001' \
-F 'file=@report.pdf'
curl --fail-with-body https://api.micropdf.dev/v1/account \
-H "Authorization: Bearer $MICROPDF_API_KEY"
curl --fail-with-body 'https://api.micropdf.dev/v1/account/usage?limit=50' \
-H "Authorization: Bearer $MICROPDF_API_KEY"
One credit is reserved per selected page. Successful pages stay
charged; failed pages release credits.
402 INSUFFICIENT_CREDITS contains no x402 challenge:
replenish credits and retry the same operation. See
billing and recovery.
Account idempotency keys accept 8–128 letters, digits, dots, underscores, colons or hyphens. Use a different value for each new extraction, and reuse the original value and identical input/options for retries. Keys are scoped to the account, so credential rotation preserves retries. Account keys cannot access previously anonymous documents.
Available scopes are documents:read,
documents:write, documents:delete, and
usage:read. Use the minimum needed. Keys can expire or
be revoked; the secret is shown only once. Contact the operator to
rotate or revoke a key until the dashboard is available.
Key-management endpoints use customer sessions, not API keys.
Usage responses contain entries and
nextCursor. Pass that cursor as before to
retrieve the next page. This cursor pagination is separate from
extraction JSON, whose pages array represents PDF
pages.
Recover without another charge
409 SYNC_TIMEOUT means extraction continues. The
downloadable client saves recovery metadata to a private
.micropdf-<idempotency-key>.json file. It never
stores your wallet private key. Keep the recovery file private; it
contains access credentials.
# Anonymous x402 recovery. Requires jq; use the saved key from the original request.
RECOVERY_FILE=".micropdf-$IDEMPOTENCY_KEY.json"
STATUS_URL="$(jq -r .statusUrl "$RECOVERY_FILE")"
RESULT_URL="$(jq -r .resultUrl "$RECOVERY_FILE")"
DOCUMENT_TOKEN="$(jq -r .token "$RECOVERY_FILE")"
curl --fail-with-body "$STATUS_URL" \
-H "Authorization: Bearer $DOCUMENT_TOKEN"
# Repeat status after 2 seconds, then back off up to 10 seconds.
# After status is succeeded:
curl --fail-with-body "$RESULT_URL" \
-H "Authorization: Bearer $DOCUMENT_TOKEN"
For API-key operations, use the response's
statusUrl and resultUrl with the same
account key; there is no document token. An async response returns
the operation directly. A sync JSON response nests it under
operation.
You can also retry the exact original request with the saved key.
Never generate a new payment because the network timed out. Stop
polling on failed or 410. For uncertain
settlement, use support.
Advanced: upload and inspect
Send one PDF as multipart field file. Inspection is
free and rate-limited. You can also send JSON with a public HTTPS
url.
Upload only inspects the PDF; it does not start
extraction.
Create and pay a quote before polling for extraction results.
curl https://api.micropdf.dev/v1/documents \
-F 'file=@report.pdf'
Save the returned id and token securely.
The token is shown once and authorizes this document’s quotes, jobs
and results. Do not put it in a URL or public log. The response
includes documentUrl (GET inspection) and
quoteUrl (POST a quote). Both require the token in the
Authorization: Bearer header; opening a link in a
browser alone will not authenticate.
# Use values from the upload response.
DOCUMENT_ID='your-document-id'
DOCUMENT_TOKEN='your-document-token'
curl "https://api.micropdf.dev/v1/documents/$DOCUMENT_ID" \
-H "Authorization: Bearer $DOCUMENT_TOKEN"
02. Create a quote
Page numbers are one-based. Omit pages to select all
pages. Use "ocr":"auto" to recognize scanned pages, or
"never" for native text only. This example assumes at
least two pages.
curl "https://api.micropdf.dev/v1/documents/$DOCUMENT_ID/quotes" \
-H "Authorization: Bearer $DOCUMENT_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"pages":[1,2],"ocr":"auto"}'
The response includes a quote id, amount,
network, expiresAt and
executeUrl, plus statusUrl for polling
payment and job state. Before payment, the status is
quoted and no extraction is queued. Amounts are integer
strings in atomic USDC units: 1000 =
0.001 USDC. Quotes currently expire after 15 minutes,
or sooner if the document expires.
03. Authorize with x402
POST to the quote’s execute URL with the document token and a stable
Idempotency-Key (8–128 letters, digits, dots,
underscores, colons or hyphens). Do not send extraction options in
this request.
QUOTE_ID='your-quote-id'
IDEMPOTENCY_KEY='a-unique-key-for-this-quote'
curl -i -X POST \
"https://api.micropdf.dev/v1/quotes/$QUOTE_ID/execute" \
-H "Authorization: Bearer $DOCUMENT_TOKEN" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY"
The server returns 402 and a
PAYMENT-REQUIRED header. Use an x402 v2 client to read
the requirements, verify the recipient, resource, network and amount
against your policy, then sign with a test wallet. Retry the same
URL and idempotency key with PAYMENT-SIGNATURE.
A successful settlement returns 202, a job ID and a
PAYMENT-RESPONSE receipt. Signing and settlement happen
in your client and the facilitator; never send your private key to
MicroPDF.
Runnable TypeScript example
Download extract.ts. It sends one synchronous extraction request, checks the recipient and spending cap, and uses the official x402 SDK to return Markdown. Node.js 24 is required. Review it before running. It submits a real testnet payment using the supplied test wallet.
npm init -y
npm pkg set type=module
npm install @x402/core@2.27.0 @x402/evm@2.27.0 @x402/fetch@2.27.0 viem@2.56.9 tsx
curl --fail --output extract.ts https://micropdf.dev/examples/extract.ts
curl --fail --output report.pdf https://micropdf.dev/samples/report.pdf
# Generate once, save locally, and reuse for this PDF on retries.
# Keep this file private. Do not create a new key after an uncertain payment.
(umask 077; node -e 'console.log(crypto.randomUUID())' > .micropdf-key)
export IDEMPOTENCY_KEY="$(cat .micropdf-key)"
export PAYMENT_ADDRESS=0xe1DFdbCB9Fc81E6c1adee349636026bfDdC7A70f
# Confirm the recipient above against the payment challenge.
# Set TEST_PRIVATE_KEY securely in your local environment.
# Use a dedicated Base Sepolia test wallet with test USDC.
API_URL=https://api.micropdf.dev \
MAX_PAYMENT_ATOMIC=50000 \
node --import tsx extract.ts report.pdf
The cap above is 0.05 test USDC. On retries, skip key generation and reload the same saved key. The example does not supply funds, manage your wallet, or enable mainnet. Learn about the protocol at x402.org.
04. Poll and retrieve
The paid job ID is the quote ID. Poll until
succeeded or failed. A successful job may
still contain partial output: check partial, each
page’s method, and all warnings.
curl "https://api.micropdf.dev/v1/jobs/$QUOTE_ID" \
-H "Authorization: Bearer $DOCUMENT_TOKEN"
# After status becomes succeeded:
curl "https://api.micropdf.dev/v1/jobs/$QUOTE_ID/result?format=markdown" \
-H "Authorization: Bearer $DOCUMENT_TOKEN"
Use format=json for the complete result. It includes
schemaVersion, pages,
markdown, warnings, and
partial. Pages contain dimensions, method
(native, ocr or failed), and
blocks. Block coordinates use PDF points with a top-left origin.
Headings, reading order and simple tables are heuristic. Images and charts are not described. Text embedded inside images on otherwise text-rich pages may be omitted. Keep source references and warnings when passing results to an agent.
Endpoint reference
| Method | Path | Purpose |
|---|---|---|
POST |
/v1/extract |
Direct results (sync) or explicit async job; x402 payment |
| GET | /health |
API liveness |
| GET | /v1/capabilities |
Current features, limits and rate |
| POST | /v1/documents |
Upload or fetch a PDF |
| GET | /v1/documents/{id} |
Inspect document |
| POST | /v1/documents/{id}/quotes |
Create immutable quote |
| POST | /v1/quotes/{id}/execute |
Pay and enqueue |
| GET | /v1/jobs/{id} |
Poll state |
| GET | /v1/jobs/{id}/result |
Fetch JSON or Markdown |
| DELETE | /v1/documents/{id} |
Delete source and results |
All document-specific routes require the bearer token from upload. The live OpenAPI specification is authoritative.
Limits and retention
- Up to 20 MB and 50 pages per document; encrypted PDFs are rejected.
- Printed English OCR. No handwriting, formula or semantic-accuracy guarantee.
- Source and results expire 24 hours after upload, including queued jobs. Delete them earlier with the endpoint below.
- Ordinary document/payment tombstones remain for up to 30 days after content expiry. Uncertain settlements remain until reconciled. Account and usage records outlive PDF expiry; logs and backups have separate lifecycles. See Privacy.
-
Uploads are limited to 5/minute; the general API limit is 120
requests/minute. Account defaults allow 5 pending jobs shared
across keys. Proxy traffic may share anonymous IP limits. A
503capacity response before payment means retry later.
curl -X DELETE \
"https://api.micropdf.dev/v1/documents/$DOCUMENT_ID" \
-H "Authorization: Bearer $DOCUMENT_TOKEN"
Deletion revokes access and removes retained source/results. Already-running processing can retain temporary data until it exits. Backups follow a separate retention policy. Assess the beta’s retention and operational limits before uploading sensitive content.
Retries without another charge
| Response | Action |
|---|---|
| 400 / 422 invalid input | Correct the file or options. Check error.code; do not repeat an unchanged invalid request. |
| 401 / 403 | Check credentials, expiry and required scopes. |
| 402 with PAYMENT-REQUIRED | x402 challenge: validate and authorize within your spending policy. |
| 402 INSUFFICIENT_CREDITS | Replenish account credits; retry the original operation without a payment signature. |
| 409 SYNC_TIMEOUT | Processing continues. Follow recovery links; do not create a new operation. |
| 409 IDEMPOTENCY_CONFLICT | The key belongs to different input/options. Recover the original operation before deciding whether to start another. |
| PAYMENT_PENDING / PAYMENT_UNCERTAIN | Stop payment retries and contact support with the quote ID. |
| 410 | The resource expired or was deleted; stop polling. |
| 429 | Honor Retry-After when present; otherwise back off with jitter. |
| 503 SYNC_BUSY / capacity | Wait and retry with the same key. No settlement occurred for this capacity rejection. |
| Network timeout / unexpected 5xx | Do not assume payment failed. Recover or retry with the original key. |
Retry a paid quote with the same idempotency key to retrieve its existing job. Do not reuse that key for another quote on the same document.
If you see PAYMENT_UNCERTAIN or
PAYMENT_PENDING, stop creating payment authorizations.
Retain your quote ID and transaction details for operator
reconciliation. Failed paid jobs also require operator resolution;
x402 refunds require manual resolution. Account page-credit
reservations are released for failed pages. See
billing rules and
support.
Other common responses: 410 for expired resources,
429 for rate limits, and 422 for
unsupported or invalid PDFs. Read the JSON
error.code and error.message; don’t infer
settlement from an HTTP timeout.