x402_fetch
Fetch URLs and automatically settle x402 payment challenges up to a set price cap, returning the response body or writing to a file for binary data.
Instructions
Fetch a URL, paying automatically if it answers with an x402 payment challenge.
SPENDS REAL MONEY when the network is mainnet. Payment comes from a short-lived session account funded from the user's vault, never from the vault itself, so the most any single call can lose is the session balance.
Returns the response body plus, when a payment happened, the price, the merchant address, the transaction id and the settlement receipt.
What the receipt proves: that this payment settled on chain. It does NOT prove the resource was correct, honest, or worth the price - a settled payment and a useful answer are different claims.
Refuses, without spending, when: the price exceeds max_price_usdc or the configured per-call cap; the day's spending cap would be exceeded; the merchant is outside an allowlist the user enabled; the resource asks for an asset this wallet does not hold; the payTo address is one of ours (paying yourself is not a payment); or a mainnet resource is not https. Each refusal says which rule it hit.
Unpaid URLs are fine - if the server answers normally, the body is returned and nothing is spent.
FILES. body_file sends the bytes at a path instead of body, and
output_file writes the response to a path instead of returning it inline. Use
them for anything binary or large - an image to be signed, a document to be
processed - because binary cannot survive being passed as text and a large body
would swamp the conversation. Both are confined to a directory the user
configured, and both are DISABLED unless they configured one; a path outside it
is refused. Pass body or body_file, never both.
JSON. Pass body as an object or array, not as a string of JSON - it is sent as
application/json and you do not need to set content_type. A string body is
sent verbatim, which is what you want for text, XML or form encoding. If the exact
bytes matter - anything the endpoint hashes or signs over - use body_file, which
is never re-encoded.
content_type sets the request's Content-Type. Some paid endpoints require it
and reject the request without it - AFTER taking payment, because the payment is
verified before the handler runs. Set it whenever the body is not plain text.
Response headers the merchant set are returned under response_headers; some
endpoints put results there that appear nowhere in the body.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| body | No | ||
| method | No | GET | |
| body_file | No | ||
| output_file | No | ||
| content_type | No | ||
| max_price_usdc | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||