Guides · Still supported
Older addresses (still supported)
Built on /scrape, /search or /recipes/...? Nothing breaks. Each one is the same tool under /tools/{id}, at the same price. Use /tools for new code.
Each older address and its tool
| Older address | The tool | Run it now with |
|---|---|---|
POST /scrape |
scrape | POST /tools/scrape |
POST /extract |
extract | POST /tools/extract |
POST /site |
site | POST /tools/site |
POST /scan |
scan | POST /tools/scan |
GET /search |
search | POST /tools/search |
GET /serp |
serp | POST /tools/serp |
GET /answer |
answer | POST /tools/answer |
POST /price |
price | POST /tools/price |
POST /monitors |
watch | POST /tools/watch |
POST /lead/people/search and the other /lead addresses |
lead | POST /tools/lead |
GET /verify, POST /verify, GET /verify/domain |
verify | POST /tools/verify |
POST /recipes/{id} |
every data tool | POST /tools/{id} |
What differs
- Request:
search,serpandanswerareGETwith a query string (1/0for booleans); through/toolsthey arePOSTwith a JSON body (true/false).leadandverifyhave one address per kind; through/toolsone tool picks withfindorcheck. - Reply: an older address answers its own body with no envelope (for example
markdownat the top level, notdata.markdown); the cost is in thex-c4-costheader. - Jobs: an older job is read at its own address (
/scrape/jobs/{id},/site/jobs/{id},/recipes/jobs/{id},/verify/jobs/{id}); every one of them also reads at/tools/jobs/{id}. - Kept only at the older address: reading or changing a watch (
/monitors/...), price history (/price/history), forgetting a verify answer.
Both are counted as the same tool in Usage.
Scrape many pages in one call
Request
# -N streams each result line as it lands
curl -N https://api.crawl4ai.com/scrape/batch \
-H "Authorization: Bearer $CRAWL4AI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"urls": ["https://a.com", "https://b.com"], "format": "md"}'import json, os, requests
with requests.post(
"https://api.crawl4ai.com/scrape/batch",
headers={"Authorization": f"Bearer {os.environ['CRAWL4AI_API_KEY']}"},
json={"urls": ["https://a.com", "https://b.com"], "format": "md"},
stream=True,
) as r:
for line in r.iter_lines():
if line:
row = json.loads(line)
print(row["url"], "ok" if row["ok"] else row["error"])const res = await fetch("https://api.crawl4ai.com/scrape/batch", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.CRAWL4AI_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ urls: ["https://a.com", "https://b.com"], format: "md" }),
});
// read the NDJSON stream line by line
const reader = res.body.getReader(), dec = new TextDecoder();
let buf = "";
for (;;) {
const { value, done } = await reader.read();
if (done) break;
buf += dec.decode(value, { stream: true });
let nl;
while ((nl = buf.indexOf("\n")) >= 0) {
const line = buf.slice(0, nl); buf = buf.slice(nl + 1);
if (line.trim()) {
const row = JSON.parse(line);
console.log(row.url, row.ok ? "ok" : row.error);
}
}
}Body
| input | type | default | what it means |
|---|---|---|---|
| urlsrequired | string[] | – | The URLs to scrape (max 50 per call). |
| timeout | number | – | Seconds, 5 to 120: the limit of the WHOLE batch. Set it a little below your HTTP client timeout. Each URL gets the time left; a URL not done in time ends with {"ok":false,"error":"sync_window_exceeded"}, free. |
| … | - | – | Any scrape input (format, proxy, country, parse) applies to every URL. |
Try it with your key
Run it in the Toolkit and see the answer, the time and the credits.
Open scrape in the ToolkitBulk jobs
You can read a job from any region: api.crawl4ai.com finds it wherever it runs.
Request
# 1. submit -> job id
JOB=$(curl -s https://api.crawl4ai.com/scrape/jobs \
-H "Authorization: Bearer $CRAWL4AI_API_KEY" -H "Content-Type: application/json" \
-d '{"urls": ["https://a.com", "https://b.com"]}' | jq -r .job_id)
# 2. poll until the job is done, or paused (stopped, or out of credit)
while :; do
S=$(curl -s https://api.crawl4ai.com/scrape/jobs/$JOB \
-H "Authorization: Bearer $CRAWL4AI_API_KEY" | jq -r .status)
case "$S" in done|paused) break;; esac; sleep 2
done
# 3. fetch results (NDJSON, one line per URL)
curl -s https://api.crawl4ai.com/scrape/jobs/$JOB/results \
-H "Authorization: Bearer $CRAWL4AI_API_KEY"import json, os, time, requests
H = {"Authorization": f"Bearer {os.environ['CRAWL4AI_API_KEY']}"}
base = "https://api.crawl4ai.com"
# 1. submit
job = requests.post(f"{base}/scrape/jobs", headers=H,
json={"urls": ["https://a.com", "https://b.com"]}).json()["job_id"]
# 2. poll until the job is done, or paused (stopped, or out of credit)
while requests.get(f"{base}/scrape/jobs/{job}", headers=H).json()["status"] not in ("done", "paused"):
time.sleep(2)
# 3. page through the results
after = 0
while True:
lines = requests.get(f"{base}/scrape/jobs/{job}/results?after={after}",
headers=H).text.splitlines()
if not lines: break
for line in lines: print(json.loads(line)["url"])
after += len(lines)const H = { "Authorization": `Bearer ${process.env.CRAWL4AI_API_KEY}`, "Content-Type": "application/json" };
const base = "https://api.crawl4ai.com";
// 1. submit
const { job_id } = await (await fetch(`${base}/scrape/jobs`, {
method: "POST", headers: H,
body: JSON.stringify({ urls: ["https://a.com", "https://b.com"] }),
})).json();
// 2. poll until the job is done, or paused (stopped, or out of credit)
let status;
do {
await new Promise(r => setTimeout(r, 2000));
({ status } = await (await fetch(`${base}/scrape/jobs/${job_id}`, { headers: H })).json());
} while (status !== "done" && status !== "paused");
// 3. fetch results (NDJSON)
const out = await (await fetch(`${base}/scrape/jobs/${job_id}/results`, { headers: H })).text();
console.log(out);Routes
| Route | Does |
|---|---|
POST /scrape/jobs |
Submit urls (max 10,000) + any /scrape field. Returns a job_id. An optional Idempotency-Key header makes a retry safe (below). |
GET /scrape/jobs/{id} |
Status + counts (pending / done / error). Add ?full=1 for per-URL detail. |
GET /scrape/jobs/{id}/results |
Streamed results, paged with ?after=N (500 per page; add &limit=N for fewer, 1 to 500). Kept 3 days after the job ends, then the job id answers 404. |
POST /scrape/jobs/{id}/retry |
Re-run just the failed URLs. |
The same job also reads at /tools/jobs/{id}, /tools/jobs/{id}/results, POST /tools/jobs/{id}/retry and DELETE /tools/jobs/{id}.
Retry a submit safely
A job is billed when it is accepted. If the answer to your submit is lost, send the same request again with
the same Idempotency-Key header: you get the first job back ("duplicate": true) and pay once.
- The key is 1 to 128 printable ASCII characters, with no space and none of
/ \ ? # %. A UUID works. - Use one new key per job. The key belongs to your account, so any of your API keys finds the job.
- A key outside this rule answers
400with{"error": "bad_idempotency_key"}, and nothing is submitted.
Try it with your key
Run it in the Toolkit and see the answer, the time and the credits.
Open scrape in the Toolkit