switch402

Web Scraping in n8n, Pay per Use: URL to Markdown with an HTTP Request Node

Scrape pages to markdown inside an n8n workflow with the built-in HTTP Request node and a prepaid switch402 key. Each successful page debits $0.003 on /v1/scrape/lite (or $0.008 on /v1/scrape); failed pages cost nothing.

Payment note: n8n's HTTP Request node does not pay x402 by itself, so this guide uses the optional prepaid key. You buy a pack once over x402 (a wallet with USDC on Base, from a script or an x402-capable client) and get a key that is shown once. Store it as an n8n credential, never in the workflow JSON.

Steps

  1. Get a prepaid key. Buy a $5, $20 (+5% credit) or $50 (+10% credit) pack once over x402 at POST https://api.switch402.com/v1/credits/buy/5 (or /20, /50). Copy the key: it is shown once.
  2. Create a Header Auth credential. In n8n add a Header Auth credential with Name Authorization and Value Bearer <your key>.
  3. Add an HTTP Request node. Method POST, URL https://api.switch402.com/v1/scrape/lite, Authentication: Generic Credential Type > Header Auth (your credential). Send a JSON body {"url": "{{ $json.url }}"} and add a User-Agent header such as my-workflow/1.0.
  4. Use the markdown. The node outputs url, title and markdown. Keep "On Error" set to continue so one failed page (502, not charged) does not stop the run.
  5. Watch the balance. GET https://api.switch402.com/v1/credits with the same credential returns balance_usd.

Code

The same request the HTTP Request node sends (curl)

curl -s -X POST https://api.switch402.com/v1/scrape/lite \
  -H "Authorization: Bearer $SWITCH402_KEY" \
  -H 'Content-Type: application/json' -H 'User-Agent: my-workflow/1.0' \
  -d '{"url": "https://example.com"}'
# 200: {"url": "...", "title": "...", "markdown": "...", "own_service": false, "ms": ..., "attempts": 1}

Check the balance

curl -s https://api.switch402.com/v1/credits -H "Authorization: Bearer $SWITCH402_KEY" -H 'User-Agent: my-workflow/1.0'
# {"key_id": "...", "balance_usd": ..., "balance_raw": ..., "plan_active_until": ...}

You pay only for the pages you actually fetch: $0.008 per standard page on /v1/scrape, $0.003 per lite call on /v1/scrape/lite, in USDC on Base and charged only on success. No subscription or unused credits; optional prepaid packs and a $10 monthly plan.

FAQ

What does a workflow cost?
Pages converted x $0.003 on lite. 1,000 pages a month cost $3.00. A $10 monthly plan (30 days) bills lite pages at a plan rate of $0.0025.
Are there rate limits on a key?
Yes: 60 calls a minute, 3,000 a day and $5 of spend a day per key.
Can n8n call the other tools?
Yes, with the same credential: /v1/map and /v1/metadata ($0.001), /v1/search, /v1/screenshot and /v1/pdf ($0.008) and /v1/screenshot/full ($0.012). Each call debits its own price, only on success.

Related