Web Scraping for AI Agents: Pay per Call over HTTP 402, No API Key
Give your agent a scrape tool it can pay for by itself. switch402 answers an unpaid call with HTTP 402 and x402 payment terms; the agent pays $0.008 USDC on Base from its own wallet and gets the page back as markdown. No signup, API key or monthly plan required. It also speaks MCP at api.switch402.com/mcp.
- HTTP 402, not API keys
The 402 response tells the agent the price and where to pay. Any x402 client signs the payment and retries.
- MCP endpoint
POST https://api.switch402.com/mcp (Streamable HTTP). Tools: scrape ($0.008), scrape_lite ($0.003), map ($0.001), metadata ($0.001), screenshot ($0.008), screenshot_full ($0.012), search ($0.008), pdf ($0.008) and quote (free).
- Charged only on success
Payment is verified first and settled only after content comes back. If every provider fails you get a 502 and pay nothing.
- Automatic failover
One endpoint in front of multiple x402 scrape providers; a failing provider is skipped for the next healthy one.
Cost: $0.008 per successful page ($0.003 on lite). An agent that reads 300 pages a month pays $2.40, with nothing to cancel.
Code example
MCP: list tools and get a free quote (curl)
curl -s -X POST https://api.switch402.com/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'User-Agent: my-agent/1.0' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
curl -s -X POST https://api.switch402.com/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'User-Agent: my-agent/1.0' \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"quote","arguments":{"url":"https://example.com"}}}'
# Paid tools (every tool except quote) return the x402 terms; retry with params._meta["x402/payment"].Python agent tool (HTTP, pays per call)
# pip install "x402[requests,evm]"
import os
from eth_account import Account
from x402 import x402ClientSync
from x402.http.clients import x402_requests
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact import ExactEvmScheme
client = x402ClientSync()
client.register("eip155:8453", ExactEvmScheme(signer=EthAccountSigner(Account.from_key(os.environ["AGENT_KEY"]))))
session = x402_requests(client)
session.headers["User-Agent"] = "my-agent/1.0"
def scrape(url: str) -> str:
"""Fetch a web page as markdown ($0.008 per successful call)."""
r = session.post("https://api.switch402.com/v1/scrape", json={"url": url})
r.raise_for_status()
return r.json()["markdown"]FAQ
- Is switch402 live?
- Yes. POST https://api.switch402.com/v1/scrape with {"url": "..."} returns the page as markdown for $0.008 USDC on Base per call, paid over x402 and charged only on success. The lite tier at /v1/scrape/lite costs $0.003.
- Does my agent need an account or API key?
- No. The agent pays per call over x402 in USDC on Base from its own wallet. There is no signup.
- Can I use it from an MCP client?
- Yes. POST https://api.switch402.com/mcp is an MCP Streamable HTTP endpoint with nine tools: scrape, scrape_lite, map, metadata, screenshot, screenshot_full, search, pdf and quote. Paid tools return x402 terms as an error result; the client retries with the payment in params._meta["x402/payment"].
- What happens if a scrape fails?
- switch402 tries the next healthy provider. If every provider fails you get a 502 and are not charged.