tally.x402 resource lets your agent call any HTTP service that uses the x402 protocol. When the service returns 402 Payment Required, the SDK parses the payment terms, pays via Tally, and retries with the on-chain proof in the X-Payment header — your agent code sees one fetch() call.
Use this for any agent that needs to pay for paywalled APIs without you hand-rolling the 402 dance every time. See the paying-x402-agent guide for an end-to-end walk-through.
Method
tally.x402.fetch(url, input)
Fetch a URL. If the service returns 402, pay via Tally and retry automatically. Returns the final HTTP response plus the receipt for the payment (if one was needed).
Types
X402FetchInput
X402FetchResult
Errors
tally.x402.fetch() throws a TallyError for SDK-side problems. Errors that originate from the underlying payments.create call (policy denial, validation, rate limiting) come through as the standard typed exceptions. x402-specific failures use these .type values:
Non-200 retry responses do not throw. Some x402 services return 4xx/5xx legitimately (rate limit, bad request, etc.) — the SDK passes the response through and you decide what to do. Check
response.ok / response.status as you would with any fetch.
Patterns
Generic tool for any LLM agent
Drop this into your LLM tool list and the agent can pay for any x402-paywalled endpoint with a single tool call:Idempotent retries
If your tool wrapper might retry the same logical x402 call (network blip, agent loop, etc.), pass a stableidempotency_key so the second attempt collapses into the first payment instead of double-spending: