- readfetch
- examples
Recipes
Eight jobs, one request each
Each recipe uses readfetch-client or @readfetch/client (latest+, x402 on paid routes) — /integrations#clients. Start with Client().probe(url) (free, no wallet). Set EVM_PRIVATE_KEY (or pass private_key / privateKey) before paid calls.
Free preflight before you pay
/v1/probe
The free start — metadata, challenge, and the extracted text: the whole read for your first 3 calls a day, a ~400-character preview after that. No x402, no wallet.
# pip install readfetch-client
from readfetch import Client
check = Client().probe("https://example.com")
print(check.get("challenge"), check.get("preview"))
// npm install @readfetch/client
import { Client } from "@readfetch/client";
const check = await new Client().probe("https://example.com");
console.log(check.challenge, check.preview);
Ingest one article into a RAG store
/v1/text
You have a URL and want the body as Markdown, with the metadata a vector store wants to filter on.
// npm install @readfetch/client
import { Client } from "@readfetch/client";
const rf = new Client({ privateKey: "0x…" });
const page = await rf.text({
url: "https://example.com/blog/post",
format: "markdown",
});
if (page.billed === false) console.warn(page.hint);
console.log({ url: page.url, title: page.title, text: page.text });
# pip install readfetch-client
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…") # funded account with USDC on Base
page = await rf.text(
{"url": "https://example.com/blog/post", "format": "markdown"}
)
if page.get("billed") is False:
print(page.get("hint"))
asyncio.run(main())
Research loop: search, then read the top results
/v1/search → /v1/text
You have a question and no URLs. One search, then a text call per result you decide to read.
// npm install @readfetch/client
import { Client } from "@readfetch/client";
const rf = new Client({ privateKey: "0x…" });
const hits = await rf.call("search", { query: "rust async runtime", limit: 5 });
for (const row of hits.results.slice(0, 3)) {
const page = await rf.fetch(row.url);
console.log({ url: page.url, title: page.title, chars: page.text?.length });
}
# pip install readfetch-client
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…") # funded account with USDC on Base
hits = await rf.call("search", {"query": "rust async runtime", "limit": 5})
for row in hits["results"][:3]:
page = await rf.text(row["url"])
print(row["url"], page.get("title"), len(page.get("text") or ""))
asyncio.run(main())
The search is one payment; each text call is another. Read three of five results, not all of them — that is the whole cost argument for doing search and reading as separate calls.
A page that only fills in after JavaScript
/v1/scrape
The HTML is a shell: the results arrive after a fetch, so text extraction gets nothing. Render it once in Chromium and wait for the selector.
// npm install @readfetch/client
// export EVM_PRIVATE_KEY=0x…
import { call } from "@readfetch/client";
const page = await call("scrape", {
url: "https://example.com/app",
mode: "render",
format: "markdown",
advanced: {
wait_for: "#results",
scan_full_page: true,
include_links: true,
},
});
# pip install readfetch-client
# export EVM_PRIVATE_KEY=0x…
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…")
page = await rf.call(
"scrape",
{
"url": "https://example.com/app",
"mode": "render",
"format": "markdown",
"advanced": {
"wait_for": "#results",
"scan_full_page": True,
"include_links": True,
},
},
)
print(page.get("billed"), page.get("hint"))
asyncio.run(main())
Use /v1/text instead whenever the content is already in the HTML — it is cheaper and it does not hold a browser slot. used_browser on a text response tells you whether a render rescued it.
Read a list of URLs for one payment
/v1/batch
A list of pages, one quote, results in the order you sent them.
// npm install @readfetch/client
// export EVM_PRIVATE_KEY=0x…
import { readfetchBatch } from "@readfetch/client";
const batch = await readfetchBatch({
urls: [
"https://example.com/a",
"https://example.com/b",
"https://example.com/c",
],
pipeline: "text",
format: "markdown",
});
# pip install readfetch-client
# export EVM_PRIVATE_KEY=0x…
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…")
batch = await rf.call("batch", {
"urls": [
"https://example.com/a",
"https://example.com/b",
"https://example.com/c",
],
"pipeline": "text",
"format": "markdown",
}
)
print(batch.get("delivered"), batch.get("credit"))
asyncio.run(main())
Priced per delivered page with a minimum, and the 402 quotes the whole list before anything runs. A page that does not deliver is not billed and shows up as credit: check billed per result, not just the top-level status.
Know when a page changes
/v1/diff
No storage on our side: you keep the hash, we tell you whether it moved and what changed.
// npm install @readfetch/client
// export EVM_PRIVATE_KEY=0x…
import { readfetchDiff } from "@readfetch/client";
const first = await readfetchDiff({ url: "https://example.com/pricing" });
const next = await readfetchDiff({
url: "https://example.com/pricing",
previous_hash: first.hash,
});
console.log(next.changed, next.diff);
# pip install readfetch-client
# export EVM_PRIVATE_KEY=0x…
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…")
first = await rf.call("diff", {"url": "https://example.com/pricing"})
nxt = await rf.call("diff",
{"url": "https://example.com/pricing", "previous_hash": first["hash"]}
)
print(nxt.get("changed"), nxt.get("diff"))
asyncio.run(main())
A no-change answer is billable: it is a fresh read of the page, not a cache hit. Send previous_content as well if you want a line diff rather than a hash comparison.
Text out of a PDF
/v1/pdf
A report, a paper or an invoice — page text plus one Markdown body, priced per document.
// npm install @readfetch/client
// export EVM_PRIVATE_KEY=0x…
import { readfetchPdf } from "@readfetch/client";
const doc = await readfetchPdf({
url: "https://example.com/report.pdf",
max_pages: 20,
});
console.log(doc.page_count, doc.billed, doc.hint);
# pip install readfetch-client
# export EVM_PRIVATE_KEY=0x…
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…")
doc = await rf.call("pdf", {"url": "https://example.com/report.pdf", "max_pages": 20})
print(doc.get("page_count"), doc.get("billed"))
asyncio.run(main())
Priced per document, so raising max_pages does not raise the price — it only bounds the work. Only %PDF- bodies are accepted; a PDF served as HTML comes back unbilled with a hint.
One section instead of a whole page
/v1/section
You need the "Authentication" part of a long API page, not forty thousand tokens of it.
// npm install @readfetch/client
// export EVM_PRIVATE_KEY=0x…
import { readfetchSection } from "@readfetch/client";
const slice = await readfetchSection({
url: "https://docs.example.com/api",
heading: "Authentication",
max_chars: 4000,
});
console.log(slice.matched, slice.chars);
# pip install readfetch-client
# export EVM_PRIVATE_KEY=0x…
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…")
slice_ = await rf.call(
"section",
{
"url": "https://docs.example.com/api",
"heading": "Authentication",
"max_chars": 4000,
},
)
print(slice_.get("matched"), slice_.get("chars"))
asyncio.run(main())
A heading that is not found is a 200 with an empty body and available_headings — pick one of those names and call again. selector works the same way for a CSS selector, up to twenty matches.
A whole site, a few pages deep
/v1/crawl → /v1/crawl/{id}
You want /blog, twenty pages, two levels. The cap is quoted before the job starts.
// npm install @readfetch/client
// export EVM_PRIVATE_KEY=0x…
import { readfetchCrawl, readfetchCrawlStatus } from "@readfetch/client";
const job = await readfetchCrawl({
url: "https://example.com",
max_pages: 20,
max_depth: 2,
include: ["/blog/*"],
});
const status = await readfetchCrawlStatus(job.job_id);
# pip install readfetch-client
# export EVM_PRIVATE_KEY=0x…
import asyncio
from readfetch import Client
async def main():
rf = Client(private_key="0x…")
job = await rf.call("crawl", {
"url": "https://example.com",
"max_pages": 20,
"max_depth": 2,
"include": ["/blog/*"],
}
)
status = await rf.call("crawl_status", None, path_params={"id": job["job_id"]})
asyncio.run(main())
Billing is per delivered page, bounded by the quoted cap. If you do not know the shape of the site yet, /v1/map returns its sitemaps, feeds and robots rules for the price of one call.
Report this call
Integrator signal — not billing.
After any call, copy X-Request-Id from the response headers (fictional id below).
// npm install @readfetch/client
import { submitFeedback } from "@readfetch/client";
await submitFeedback(
"demo-req-0001",
"integration",
"402 body did not match my client parser",
);
# pip install readfetch-client
import asyncio
from readfetch_client import submit_feedback
async def main():
await submit_feedback(
"demo-req-0001",
"integration",
"402 body did not match my client parser",
)
asyncio.run(main())
When a recipe returns billed: false
On reading routes, billed: false means nothing was charged; the response carries a hint naming the next call: a wall → /v1/scrape, empty text → render, binary body → /v1/fetch. On /v1/fetch, check status_code — origin 4xx/5xx can still be billed: true. /SKILL.md has the full symptom table; /choose picks the endpoint first.