Turn web pages and PDFs into clean Markdown chunks for RAG, paid per call

Agents · 7 min read · last reviewed 2026-11-12

Retrieval-augmented generation (RAG) is only as good as the text you index. Raw HTML brings menus, cookie banners, footers and "related posts" into your vector store, and PDFs need a separate extraction step. Then everything has to be cut into chunks small enough to embed.

This guide shows how an agent or an ingestion script can do all three steps with pay-per-call tools in our Lordevo Shop: clean Markdown from a URL, text from a PDF, and heading-aware chunks. Each call costs $0.0021, paid with x402 in USDC on Base. There is no account and no API key, and every fetch obeys the site's robots.txt. If the payment step is new to you, start with what x402 is.

The tools and what they cost

ToolWhat it doesPrice per call
page-markdownOne public web page as clean Markdown (main content only), plus title, description, language, canonical, dates, word count and a token estimate$0.0021
page-markdown-batchThe same for 1 to 5 URLs in one call$0.005
pdf-textThe text layer of one public PDF, page by page$0.0021
text-chunkSplits text you send, or the main content of one page, into heading-aware chunks with optional overlap$0.0021
token-countA token estimate for a text, with a low and high range$0.0021
can-fetchWhether robots.txt allows this exact URL, for generic agents and 16 named AI crawlers$0.0021

A batch of 5 URLs costs the same per URL as five single calls. For 1 to 4 URLs, single calls are cheaper.

Step 1: try a page for free

The shop gives 3 free calls per IP address per UTC day on tools priced up to $0.0022, which includes page-markdown, pdf-text and text-chunk. Add trial=1:

curl "https://shop.lordevo.com/api/quick/page-markdown?url=https://example.com&include_links=false&trial=1"

The answer has the Markdown in markdown, plus title, lang, canonical, word_count, markdown_tokens and a content_sha256 you can use to skip pages that have not changed since your last crawl. page-markdown removes navigation, cookie banners, footers, share bars and related-post blocks, and keeps headings, lists, tables (as pipe tables) and code blocks. Use include_links=false to drop link targets and images, and max_tokens (100 to 100,000) to cut long pages at a block boundary; the answer then says truncated: true.

Step 2: check a PDF before you pay

Fetch tools have a free preflight that tells you whether a paid call would work on a URL (reachability, robots.txt, content type and size) without returning any content:

curl "https://shop.lordevo.com/api/free/preflight?url=https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf&tool=pdf-text"

pdf-text returns pages (each with page, text and characters), page_count and the PDF's title metadata. Know its limits before you rely on it: 10 MB, 50 pages and 500,000 characters per PDF. Password-protected PDFs are refused, and scanned pages are not OCRed, so an image-only PDF comes back with no text. Layout and tables are not rebuilt.

Step 3: chunk for your vector store

text-chunk splits along Markdown headings and paragraphs first, then sentences. Each chunk carries its heading_path (for example ["Pricing", "Refunds"]), its text and an approximate token count. max_tokens sets the chunk size (50 to 4,000, default 500) and overlap_tokens repeats the end of the previous chunk (default 50, at most half of max_tokens). There are two ways to call it:

  • One call per web page: text-chunk?url=… fetches the page's main content and chunks it, for $0.0021 per page.
  • Text you already have: POST {"text": "…"} with up to 400,000 characters. Use this after pdf-text, or after page-markdown when you also want to keep the Markdown and its metadata.

Token counts here and in token-count are estimates from a documented heuristic, not an exact tokenizer; the shop says they are typically within about 15% for English. Leave headroom below your embedding model's limit.

A complete ingestion script

This script reads a list of sources, sends PDFs through pdf-text and then text-chunk, sends web pages straight to text-chunk, and writes one JSON line per chunk to chunks.jsonl, ready for your embedding step. Payments come from the wallet behind AGENT_WALLET_KEY, capped at $0.0021 each; how an AI agent pays for an API covers the wallet setup. Node 20 or newer, with version 2.23.0 or later of the @x402 packages.

// npm i @x402/fetch @x402/core @x402/evm viem
// Save as ingest.mjs, then run: AGENT_WALLET_KEY=0x... node ingest.mjs
import fs from 'node:fs';
import { wrapFetchWithPayment } from '@x402/fetch';
import { x402Client } from '@x402/core/client';
import { ExactEvmScheme } from '@x402/evm/exact/client';
import { privateKeyToAccount } from 'viem/accounts';

const SHOP = 'https://shop.lordevo.com';
const client = x402Client.fromConfig({
  schemes: [{ network: 'eip155:8453', client: new ExactEvmScheme(privateKeyToAccount(process.env.AGENT_WALLET_KEY)) }],
  spendControls: { maxAmountPerPayment: '$0.0021' }, // refuse any payment above this
});
const pay = wrapFetchWithPayment(fetch, client);
const sources = [
  'https://example.com/',
  'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
];
// One paid call. Answers of 400 or higher are not charged and are thrown as errors here.
const get = async (path, init) => {
  const r = await pay(SHOP + path, init);
  const j = await r.json();
  if (r.status >= 400) throw new Error(r.status + ' ' + (j.error || ''));
  return j;
};
const out = fs.createWriteStream('chunks.jsonl');
for (const url of sources) {
  try {
    let res;
    if (/\.pdf($|\?)/i.test(url)) {
      const pdf = await get('/api/quick/pdf-text?url=' + encodeURIComponent(url));
      const text = pdf.pages.map(p => p.text).join('\n\n');
      res = await get('/api/quick/text-chunk', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text, max_tokens: '500', overlap_tokens: '50' }) });
    } else {
      res = await get('/api/quick/text-chunk?url=' + encodeURIComponent(url) + '&max_tokens=500&overlap_tokens=50');
    }
    for (const c of res.chunks) out.write(JSON.stringify({ source: url, chunk: c.index, heading_path: c.heading_path, tokens: c.approx_tokens, text: c.text }) + '\n');
    console.log(url, res.chunk_count, 'chunks');
  } catch (e) { console.log(url, 'skipped:', e.message); }
}
out.end();

Cost: $0.0021 per web page and $0.0042 per PDF. A 1,000-page site costs $2.10 to chunk this way. If you add page-markdown-batch, raise the cap to $0.005.

Respecting the sites you read

Every fetch tool in the shop checks robots.txt for the URL and for every redirect. If a site does not allow it, the answer is 403 robots_disallowed and you are not charged. To know before you plan a crawl, can-fetch ($0.0021) reports the robots.txt verdict for generic agents and for named AI agents such as ChatGPT-User, Claude-User, GPTBot and ClaudeBot, plus Content-Signal and X-Robots-Tag hints such as noai, without downloading the page. It applies the robots.txt rules in RFC 9309.

Being allowed to fetch a page is not the same as being allowed to reuse its content. Check the site's terms and copyright before you put third-party text into a product.

When you are charged

  • Answers below 400 are charged. Anything of 400 or higher is not, and the body says "charged": false.
  • page-markdown-batch returns a per-URL error for pages it cannot read, and charges nothing if every URL fails.
  • The full rules are in the shop's error reference. Every tool, price and parameter is in llms.txt and on the quick checks page, and our agent directory lists more x402 and MCP tools. For a different job with the same setup, see bulk domain lookups for lead lists.

How this was checked: on 10 November 2026 the original script ran against a test copy of the shop (Base Sepolia test network, test facilitator, throwaway key). The version above, with the cap, ran on 12 November 2026 with @x402 2.29.0 against a local stub seller, with no network and no real money. Prices are from the shop's price list on 12 November 2026.

Questions

How much does it cost to turn a web page into Markdown?

$0.0021 per page with page-markdown on the Lordevo Shop, paid per call with x402 in USDC on Base. page-markdown-batch reads up to 5 URLs for $0.005.

Can it read PDFs?

Yes. pdf-text returns the text layer of a public PDF page by page for $0.0021 per call, up to 10 MB, 50 pages and 500,000 characters. Scanned pages are not OCRed and password-protected PDFs are refused.

How are the chunks split?

text-chunk follows Markdown headings and paragraphs, then sentences. Each chunk has its heading path and an approximate token count. Chunk size is 50 to 4,000 tokens (default 500), with optional overlap (default 50).

Does it respect robots.txt?

Yes. Every fetch checks robots.txt for the URL and each redirect. A disallowed URL returns 403 robots_disallowed and is not charged.

Can I try it without a wallet?

Yes. Add trial=1 to the query for 3 free calls per IP address per UTC day on tools priced up to $0.0022, including page-markdown, pdf-text and text-chunk.

Try a pay-per-call tool

Web, domain and data checks for agents over x402, in USDC on Base. No account and no API key. Prices and inputs for every tool are in the catalogue.