Use case · RAG and knowledge for LLMs
Web scraping for RAG: any website to LLM-ready Markdown.
To feed a RAG pipeline from the web, you need three things: the list of page URLs, each page as clean text, and a way to see which pages changed. Crawl4AI Cloud, the data toolkit for AI agents (109 tools, one key, one API), does each with one HTTP call: the scrape tool reads a sitemap or a page, /tools/batch returns many pages as Markdown, and every answer carries a content_hash you compare on the next run.
1What does a RAG crawl need?
A RAG pipeline (retrieval-augmented generation: the model reads pages you give it before it answers) is only as good as the text you put in. From the web, that text must be clean: no menus, no cookie banners, no scripts. It must also keep the headings, because your chunker uses them to cut the page.
The work has three steps. Find the URLs. Fetch each page as Markdown. On the next run, find what changed. The calls below do each step. The outputs on this page are real answers from the live API on 10 November 2026, shortened where it says so; the scrape answers are shown in the /tools envelope.
Step 1: find the URLs
Most sites list their pages in /sitemap.xml. Fetch it with the scrape tool and read the <loc> lines. A page we already hold in our archive costs half.
curl -X POST https://api.crawl4ai.com/tools/scrape \
-H "Authorization: Bearer $CRAWL4AI_API_KEY" -H "Content-Type: application/json" \
-d '{"url":"https://docs.crawl4ai.com/sitemap.xml","format":"html"}'
{"tool":"scrape","request_id":"req_...","took_ms":17,"usage":{"credits":0.05},
"data":{"engine":"archive","cache":"archive","text_len":5219,
"html":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset ...>\n <url>\n <loc>https://docs.crawl4ai.com/</loc>\n <lastmod>2026-10-26</lastmod> ..."}}
Shortened: the sitemap held 89 <loc> lines. The page fields sit under data.
No sitemap? Fetch the home page with "parse":{"links":true} and keep the links on the same host.
Step 2: fetch the pages as Markdown
Send up to 50 URLs in one /tools/batch call with "stream":true. The answer streams back as NDJSON, one line per URL as it finishes. For a long list (up to 10,000 URLs), leave stream out: the batch runs as a job in the background and nothing waits on a slow page. Follow it at GET /tools/jobs/{job_id} and read the pages at /tools/jobs/{job_id}/results.
curl -N -X POST https://api.crawl4ai.com/tools/batch \
-H "Authorization: Bearer $CRAWL4AI_API_KEY" -H "Content-Type: application/json" \
-d '{"tool":"scrape","stream":true,"inputs":[
{"url":"https://docs.crawl4ai.com/core/cache-modes","format":"md"},
{"url":"https://docs.crawl4ai.com/core/ask-ai"}]}'
{"url":"https://docs.crawl4ai.com/core/cache-modes","ok":true,"result":{"engine":"fetch","ms":952,"text_len":4120,"content_hash":"65d80f7e9f8a...","markdown":"..."}}
{"url":"https://docs.crawl4ai.com/core/ask-ai","ok":true,"result":{"engine":"browser-light","ms":10837,"text_len":2411,"content_hash":"50f45758e980...","markdown":"..."}}
Real answer, shortened. The first page needed only a plain fetch. The second needed a browser, so it took 10.8 s.
One page alone is a scrape call. This is its answer for the library's quick-start page, in the /tools envelope:
{"tool":"scrape","request_id":"req_...","took_ms":440,"usage":{"credits":0.1},
"data":{"engine":"http","cache":"miss","text_len":24163,
"final_url":"https://docs.crawl4ai.com/core/quickstart/",
"content_hash":"7759a795ab401dca600d0d52082cf0c49c0c78e103fce1e2a01da9d9dea42024",
"ladder":[{"rung":"http","outcome":"sounder:http","ms":117}],
"markdown":"... # Getting Started with Crawl4AI\n\nWelcome to **Crawl4AI**, an open-source LLM-friendly Web Crawler & Scraper. In this tutorial, you’ll:\n\n1. Run your **first crawl** using minimal configuration.\n2. Generate **Markdown** output ..."}}
Shortened. data.ladder lists the steps the service tried, in order.
2How do I re-embed only the pages that changed?
Every scrape answer carries a data.content_hash of the page content. Store it next to the URL. On the next run, fetch the pages again and compare. The same hash means the same content: skip the page. A new hash means new content: re-chunk and re-embed that page only. A URL that left the sitemap is a page to delete from the index.
This keeps the embedding bill small, because most pages of a docs site or a knowledge base do not change from one week to the next.
For a few pages that must be fresh the same day (a pricing page, a status page, a policy), Watch (in beta) checks the page for you and calls your webhook when it changes. See the Watch docs.
3Can my agent search the web and read the results?
Yes. POST /tools/search returns ranked results with title, URL and snippet in rows. Your agent then reads the pages it needs with the scrape tool. A search costs 1 credit.
curl -X POST https://api.crawl4ai.com/tools/search \
-H "Authorization: Bearer $CRAWL4AI_API_KEY" -H "Content-Type: application/json" \
-d '{"q":"retrieval augmented generation chunking"}'
{"tool":"search","request_id":"req_...","took_ms":1501,"usage":{"credits":1},"rows":[
{"title":"Chunking Methods on Retrieval-Augmented Generation","url":"https://arxiv.org/html/2606.00881v1","source":"gg","snippet":"May 30, 2026 — A standard RAG pipeline initially splits documents ..."},
{"title":"Develop a RAG Solution on Azure - Chunking Phase","url":"https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/rag/rag-chunking-phase","source":"gg","snippet":"Jun 18, 2026 — Chunking is breaking documents into appropriately sized chunks ..."}, ...]}
Shortened to 2 of 10 rows, shown in the /tools envelope.
In Claude Code, Cursor, Codex or any MCP client, add the hosted MCP server once. The agent then has scrape, search, batch and jobs_submit as tools. Agents that use HTTP start at GET https://api.crawl4ai.com/tools?q=search, which needs no key:
claude mcp add --transport http crawl4ai https://api.crawl4ai.com/mcp \
--header "Authorization: Bearer $CRAWL4AI_API_KEY"
Agents can read the whole API from one file: crawl4ai.com/llms.txt. More in the MCP docs.
4What does a RAG crawl cost?
You pay for the effort each page needed. A failed call costs nothing. One credit is $0.001 at list price.
| Page | Credits a page | Per 1,000 pages |
|---|---|---|
| Already in our archive | 0.05 | $0.05 |
| Plain fetch | 0.1 | $0.10 |
| Real browser | 0.5 | $0.50 |
| Hard site (the site fought back) | 2 | $2.00 |
| Failed (blocked, no answer) | 0 | $0 |
From GET /v1/prices (by_level.scrape), read 10 November 2026. A search is 1 credit.
Example, not a measurement: a docs site of 2,000 pages, 80% plain and 20% that need a browser, costs 1,600 × 0.1 + 400 × 0.5 = 360 credits, so $0.36 at list price. The free plan gives 1,000 credits every month. Paid plans: Starter $10 a month with 10,000 credits, Builder $99 with 125,000, Scale $499 with 750,000. See pricing.
5How do I load the pages into LangChain or LlamaIndex?
Read the NDJSON lines and turn each page into a document with its URL and hash as metadata. Your splitter and vector store stay as they are. This short Python example uses only the standard library and requests:
import json, os, requests
KEY = os.environ["CRAWL4AI_API_KEY"]
urls = ["https://docs.crawl4ai.com/core/cache-modes", "https://docs.crawl4ai.com/core/ask-ai"]
BASE = "https://api.crawl4ai.com"
r = requests.post(f"{BASE}/tools/batch",
headers={"Authorization": f"Bearer {KEY}"},
json={"tool": "scrape", "stream": True,
"inputs": [{"url": u, "format": "md"} for u in urls]},
stream=True, timeout=120)
docs = []
for line in r.iter_lines():
row = json.loads(line)
if "summary" in row or not row.get("ok"):
continue
res = row["result"]
docs.append({"text": res["markdown"],
"metadata": {"url": row["url"], "content_hash": res["content_hash"]}})
# docs -> your splitter (for example MarkdownHeaderTextSplitter) -> your vector store
6Should I run the open-source library or use the Cloud?
Crawl4AI Cloud runs the same engine as the open-source Crawl4AI library. The library gives the same Markdown on your own machine, for free. You then run the browsers, buy the proxies and handle the sites that block you. The Cloud does that part and charges only for pages that worked.
For a small docs site with no blocks, the library is often enough. For many sites, pages that need a browser, or sites that block plain requests, compare the numbers on build vs buy.
7Questions
Is Markdown better than HTML for RAG?
For most RAG pipelines, yes. Markdown keeps the headings, lists, tables and links that tell the model how a page is built, and drops the scripts, styles and menus. It also uses fewer tokens than the same page as HTML, so more real text fits in each chunk.
How do I keep the index fresh?
Store the content_hash that every scrape answer carries. On the next run, fetch the pages again and compare the hashes. Re-embed only the pages whose hash changed, and delete the chunks of pages that are gone.
Can it read pages that need JavaScript?
Yes. The service tries a plain fetch first and moves to a browser only when the page needs one. The data.engine field of each answer says which one served the page. A browser page costs 0.5 credit instead of 0.1.
What happens when a site blocks the request?
You get a 403 with the reason blocked or login-wall, or a 502 when the site did not answer. These calls are not charged. Log the URL and skip it; a retry rarely helps.
Do you train models on my pages?
No. The pages you fetch and the instructions you send are used only to answer your request. We do not sell customer data. See the security page.
How is this different from running the open-source Crawl4AI library?
The engine is the same. The open-source library is the open-source crawler: you run the browsers, buy the proxies and handle blocked sites. Crawl4AI Cloud is the data toolkit for AI agents: you send an HTTP request to one of 109 tools and we run that part. Failed calls are free.
Next: market intelligence · build vs buy · tools docs · scrape docs
Older addresses (still supported): /scrape, /scrape/batch (use it to stream more than 50 pages), /scrape/jobs and /search take the same inputs. For new code, use /tools. See /scrape/batch and /scrape/jobs.