How to integrate DeathByCaptcha into RAG pipelines
A RAG pipeline is only as good as the corpus behind it. The model can be perfect and the embeddings fresh, but if the crawl that feeds the index was stopped by a Cloudflare Turnstile on a Friday night, the retrieval will quietly answer from a corpus that is missing the pages you care about.
That is the argument for treating CAPTCHA solving as part of ingestion infrastructure, the same way you treat retries, rate limits and backoff.
Where the challenge shows up in a pipeline
Most RAG systems start by fetching documents: sitemaps, feeds, product pages, documentation, forum threads. The fetch stage meets the same defences any scraper meets:
- a 403 or 429 with a Cloudflare Turnstile or an Amazon WAF challenge;
- a login or registration form guarded by reCAPTCHA;
- a DataDome interstitial in front of the document;
- an image CAPTCHA on a form that gates the data.
Every one of those events ends the document's path to your index if the pipeline does nothing. The failure is silent: no exception reaches the embedding step, and the index simply has one fewer document.
source → fetch → challenge? ─yes→ DeathByCaptcha → token or cookie
│ │
no ↓
↓ retry fetch
document ──────────────────┘
↓
parse → chunk → embed → index
The integration point: the fetch, before the parse
Solving belongs in the transport layer of your ingestion code, not in the model. Three shapes cover most stacks:
1. Requests-based or Scrapy ingestion. The downloader middleware
intercepts the challenge, sends it to DeathByCaptcha and retries the
request with the cookie or header the site expects. This is the example
shipped in the Node and Python clients (examples/scrapy/), and it works
without a browser for the cookie-based types: Amazon WAF, DataDome and
Turnstile where a cookie is what is validated.
2. Browser-based ingestion. When the pipeline drives a real page with Playwright or Puppeteer, the token types are what you need: reCAPTCHA v2 and v3, Turnstile and WAF. The samples in those repositories extract the sitekey, request the token, inject it and continue; the crawl then keeps its session and cookies.
3. Orchestrated pipelines. If your ingestion runs in n8n or in an agent, the same API is a single step: the n8n workflow example solves the challenge and passes the token to the next node, and an agent can call it as a tool. The pattern does not change, only the orchestrator.
A minimal sketch
def fetch_document(url, session):
response = session.get(url, timeout=30)
if not is_challenge(response):
return response
solution = client.decode(
type=16,
waf_params=json.dumps({
"sitekey": extract_sitekey(response.text),
"pageurl": url,
"proxy": proxy, # same exit IP as the crawler
"proxytype": "HTTP",
}),
)
if not solution:
return None # mark the document as missing, never fake it
session.cookies.set("aws-waf-token", solution["text"])
return session.get(url, timeout=30)
Two rules in that sketch are not optional: the proxy keeps the crawler and
DeathByCaptcha on the same exit IP for the token types that are bound to
it, and a failure returns None so the document is recorded as missing
instead of being indexed from a partial parse.
Operational rules
- Budget per run. Decide how many solves a crawl may spend before it stops and pages an operator. At $0.00289 per token solve, a thousand challenges cost about $2.89; that is cheap, an unbounded loop is not.
- Retry caps. Two attempts, then the document goes to the "missing" bucket with its URL, status and captcha id.
- Log the captcha id, never the token. The id is enough to report or refund a bad solve; the token is single-use and meaningless to logs.
- Respect the source. Rate limits, robots rules and the terms of the site still apply: solving a challenge is not permission to hammer a server.
- Keep the corpus honest. A document you could not fetch is missing data. Mark it, retry it on the next refresh, and never index a placeholder as if it were content.
Why this belongs in the retrieval budget
The cost of a solve is small compared with the cost of answering from an incomplete index: a wrong recommendation, a stale price, a policy answer that no longer exists on the source page. Scheduled re-crawls make it worse if every refresh quietly loses the same protected pages — the index looks healthy while a whole domain is absent.
Placing DeathByCaptcha at the fetch step turns an anti-bot wall into a measured, budgeted line item: the crawl either gets the document or records why it did not.
Next steps
- Scrapy middleware example (Python client): https://github.com/deathbycaptcha/deathbycaptcha-api-client-python
- Playwright and Puppeteer samples (Node client): https://github.com/deathbycaptcha/deathbycaptcha-api-client-nodejs
- n8n workflow example:
examples/n8n/in the same repository. - Agent metadata for pipeline tooling: https://github.com/deathbycaptcha/deathbycaptcha-agent-api-metadata
- API documentation: https://deathbycaptcha.com/api
If your pipeline already retries, solves nothing and drops the page on failure, the change is one branch in the fetch function and a budget in the settings.

English
Spanish
Russian
Chinese
French
Hindi
Arabic
Bengali
Indonesian
Portuguese
com, 