switch402

PDF to Text API for RAG and AI Agents: $0.008 per Call, Page by Page

Send the URL of a public PDF and get its text back page by page, ready to chunk and embed. /v1/pdf costs $0.008 USDC on Base per call, for up to 50 pages and 10 MB, paid over x402 with no subscription or API key. You are charged only when text comes back.

  • Text page by page

    The response has the full text plus a pages array ({page, text}), page_count, title and author, so every chunk can keep its page number for citations.

  • Choose the pages

    Up to 50 pages per call. Pick them with pages like "1-3,7" or [1, 2, 3]; without it, extraction starts at page 1. A 120-page PDF takes 3 calls.

  • No OCR

    switch402 reads the text layer already in the PDF. A scanned PDF with no text layer, or a password-protected one, returns 422 and is not charged.

  • Size and URL limits

    Public http(s) URLs only. The PDF must be 10 MB or less and the server must declare its size (Content-Length or Content-Range); otherwise 422, not charged. Text is capped at 500,000 characters (truncated: true when cut).

Cost: $0.008 per call of up to 50 pages. A 30-page report costs $0.008; a 120-page manual takes 3 calls (pages 1-50, 51-100, 101-120) for $0.024. Failed, scanned or password-protected PDFs cost nothing.

Ingesting web pages too? See the Firecrawl pricing calculator.

Working in Python? See PDF text extraction in Python.

Code example

Python: PDF to page-tagged chunks for a vector store

# pip install "x402[requests,evm]"
import os
from eth_account import Account
from x402 import x402ClientSync
from x402.http.clients import x402_requests
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact import ExactEvmScheme

client = x402ClientSync()
client.register("eip155:8453", ExactEvmScheme(signer=EthAccountSigner(Account.from_key(os.environ["AGENT_KEY"]))))
session = x402_requests(client)
session.headers["User-Agent"] = "my-agent/1.0"

def pdf_chunks(url: str, pages: str | None = None) -> list[dict]:
    """PDF text page by page ($0.008 per successful call, up to 50 pages)."""
    body = {"url": url, **({"pages": pages} if pages else {})}
    r = session.post("https://api.switch402.com/v1/pdf", json=body)
    if r.status_code == 422:
        return []  # scanned (no text layer), password-protected or size not declared: not charged
    r.raise_for_status()
    doc = r.json()  # {"url", "page_count", "pages_returned", "title", "author", "truncated", "text", "pages"}
    return [
        {"text": p["text"], "source": doc["url"], "page": p["page"], "title": doc.get("title")}
        for p in doc["pages"] if p["text"].strip()
    ]

chunks = pdf_chunks("https://arxiv.org/pdf/1706.03762", pages="1-3")

curl: an unpaid call shows the price (HTTP 402)

curl -i -G https://api.switch402.com/v1/pdf \
  -H 'User-Agent: my-agent/1.0' \
  --data-urlencode 'url=https://arxiv.org/pdf/1706.03762' \
  --data-urlencode 'pages=1-3'
# HTTP 402 with x402 payment terms ($0.008); an x402 client pays and retries.

FAQ

Is the PDF to text API live?
Yes. GET https://api.switch402.com/v1/pdf?url=... (or POST {"url": "...", "pages": [1, 2]}) returns the PDF's text page by page for $0.008 USDC on Base per call, paid over x402. An unpaid call answers HTTP 402 with the exact terms.
What are the limits?
Up to 50 pages and 10 MB per call, text up to 500,000 characters (truncated: true when cut). The PDF must be at a public http(s) URL whose server declares the file size (Content-Length or Content-Range); otherwise you get 422 and are not charged. Longer PDFs need one call per 50 pages.
Does it OCR scanned PDFs?
No. It reads the text layer already in the PDF and does no OCR. A scanned PDF with no text layer returns 422 and is not charged, so run OCR elsewhere for scans.
Does it keep tables and layout?
It returns plain text per page, not structured tables or positions. Columns and tables come back as text, so check a sample of your documents before you rely on it.
Can I upload a local file?
No. The input is a public PDF URL. Password-protected PDFs and URLs that do not return a PDF are rejected and not charged.
Am I charged if extraction fails?
No. Payment settles only when text comes back. Repeated failed PDF calls from one payer within 10 minutes can be rate-limited (429, not charged).

Next steps