Retrieval-augmented generation (RAG) answers questions from text you have indexed. If that text came straight from HTML, your vector store is full of navigation menus, cookie notices, footers and "you may also like" blocks. Those chunks match queries they have nothing to do with, and the model quotes them back to your users.
The usual fix is to turn each page into clean Markdown first: main content only, with the headings kept so chunks know where they came from. This guide covers what that step has to get right, the ways to do it, and what it costs if you pay per page instead of per month.
In short: A good converter keeps the main content and its structure, drops page furniture, respects robots.txt and tells you roughly how many tokens you got. You can run an open-source extractor yourself, buy a scraping plan, or pay per page. In our shop, page-markdown costs $0.0021 a page ($2.10 per 1,000), paid per call with x402 and no account. Try 3 pages a day free before you decide.
Why Markdown and not plain text
Plain text loses the structure that makes retrieval work. Markdown keeps it in a form a model reads well:
- Headings tell a chunker where sections start, and let each chunk carry its section path, such as "Pricing > Refunds".
- Lists and tables stay readable instead of collapsing into one long line.
- Code blocks keep their line breaks.
It is also compact. A page's Markdown is usually much shorter than its HTML, and you pay for every token you embed and every token you put into a prompt.
What a good converter must do
Whichever option you choose, test it against this list on a few of your real pages:
- Keep the main content only. Navigation, cookie banners, footers, share bars and related-post blocks should be gone.
- Keep the structure. Headings, nested lists, tables and code blocks should survive.
- Return useful metadata. Title, language, canonical URL and the published date when the page states one help you filter and cite.
- Estimate tokens. You need to know whether a page fits your chunk size and your context window.
- Respect robots.txt. A site that disallows your fetch should be skipped, not scraped anyway.
- Handle PDFs too. Documentation, price lists and reports are often PDFs, and they need a separate text extraction step.
- Cope with JavaScript-built pages. Some sites send an almost empty page and build the content in the browser. Check what your converter returns for those; our guide on JavaScript sites that look empty to crawlers explains the problem.
Your three options
Run an open-source extractor yourself
There are good free libraries that pull the main content from HTML and convert it to Markdown.
- Cost: no per-page fee, but you run the fetching, the servers and the upkeep.
- Work for you: robots.txt checks, retries, timeouts, character encodings, PDFs and the pages the extractor gets wrong.
- Best when: you crawl a lot, steadily, and have someone to maintain it.
Buy a scraping API plan
Hosted scraping services do the fetching and conversion for you, usually on a monthly plan with a credit allowance.
- Cost: a fixed monthly fee, whether you use the credits or not.
- Work for you: an account, a key and a plan to choose.
- Best when: your volume is steady and predictable.
Pay per page with x402
Pay-per-call tools charge for each request, with no account. The agent or script pays in USDC on the Base network through x402, a protocol that uses the HTTP 402 Payment Required status. If x402 is new to you, our guide What is x402? explains it in four steps.
- Cost: only the pages you fetch.
- Work for you: a small wallet and an x402 client library.
- Best when: volume is irregular, or an agent decides at run time which pages to read.
We sell this option, so weigh that when you read the next section.
What paying per page costs
These are the RAG tools in our Lordevo Shop and their prices per call:
| Tool | What it does | Price per call |
|---|---|---|
| page-markdown | One public web page as clean Markdown, with title, language, canonical, dates, word count and a token estimate | $0.0021 |
| page-markdown-batch | The same for 1 to 5 URLs in one call | $0.005 |
| pdf-text | The text layer of one public PDF, page by page | $0.0021 |
| text-chunk | Heading-aware chunks of text you send, or of one page's main content | $0.0021 |
| token-count | A token estimate for a text, with a low and high range | $0.0021 |
So a full job costs:
| Pages | Markdown only | Markdown, then chunked |
|---|---|---|
| 100 | $0.21 | $0.42 |
| 1,000 | $2.10 | $4.20 |
| 10,000 | $21.00 | $42.00 |
You can often skip a step. text-chunk with a url fetches a page's main content and chunks it in one call, so chunking a 1,000-page site that way costs $2.10. Use page-markdown first only when you also want to keep the Markdown and its metadata. A batch of 5 URLs costs the same per URL as five single calls; for 1 to 4 URLs, single calls are cheaper.
Limits worth knowing before you rely on it
- page-markdown returns up to 60,000 characters per page. A max_tokens option cuts long pages at a block boundary and marks the answer as truncated.
- pdf-text handles PDFs up to 10 MB, 50 pages and 500,000 characters. Password-protected PDFs are refused, and scanned pages are not OCRed, so an image-only PDF comes back with no text.
- Token counts are estimates from a documented heuristic, not an exact tokenizer. The shop says they are typically within about 15% for English, so leave headroom below your embedding model's limit.
- Every fetch obeys robots.txt for the URL and each redirect. A disallowed page answers 403 robots_disallowed and is not charged.
Being allowed to fetch a page is not the same as being allowed to reuse it. Check the site's terms and copyright before you put someone else's text into a product.
A full ingestion script
Our guide Web pages and PDFs to Markdown chunks for RAG has a complete Node script. It reads a list of URLs, sends PDFs through pdf-text and then text-chunk, sends web pages straight to text-chunk, and writes one JSON line per chunk, ready for your embedding step. Payments are capped at $0.0021 each. The wallet setup is in How can an AI agent pay for an API?.
With our SDK
From your own code, the lordevo-x402 client (version 0.1.5) gives each tool a method:
npm i lordevo-x402@0.1.5
# for paid calls, also:
npm i @x402/fetch @x402/evm viem
import { fromPrivateKey } from 'lordevo-x402';
const lordevo = await fromPrivateKey(process.env.AGENT_WALLET_KEY, { maxPriceUsd: 0.02 });
const md = await lordevo.pageMarkdown({ url: 'https://example.com/' });
const chunks = await lordevo.textChunk({ url: 'https://example.com/post', max_tokens: 300 });
The shop's framework guides (LangChain, CrewAI, the Vercel AI SDK, MCP clients and more) are at shop.lordevo.com/guides/sdk.
Try a page for free
Add trial=1 for 3 free calls per IP address per UTC day on tools up to $0.0022, which includes page-markdown, pdf-text and text-chunk:
curl "https://shop.lordevo.com/api/quick/page-markdown?url=https://example.com&include_links=false&trial=1"
Run it on a few of the pages you actually plan to index, including a long one and one built with JavaScript, and compare the Markdown with what you see in the browser. The shop's start page has setups for curl, JavaScript, Python and MCP, and its error reference lists when a call is and is not charged.
Key takeaways
- Index clean Markdown, not raw HTML, so menus and banners stay out of your answers.
- Keep headings: they make better chunks and let each chunk carry its section path.
- Test any converter on your own pages, including PDFs and JavaScript-built pages.
- Self-hosting suits steady, high volume; plans suit predictable volume; pay-per-page suits irregular volume and agents.
- Respect robots.txt and the site's terms, not only one or the other.