fetch() call into a complete payment flow. Your agent never touches wallets, protocols, or transaction signing directly. The SDK handles everything behind the scenes.
The Payment Flow
When your agent callsagent.fetch(url), here is what happens under the hood:
Step by Step
-
Probe — The SDK sends a regular GET request to the endpoint. If the server returns
200, the response passes through as-is. No payment needed. -
402 Detection — If the server returns
402 Payment Required, the SDK inspects the response headers and body to determine which payment protocol is in use (x402, L402, or a hybrid format). -
Quote — The SDK extracts the price, currency, network, and facilitator address from the 402 response. This is the same information you get from
agent.quote(url). -
Budget Check — Before any money moves, the SDK validates the price against your configured budget limits (per-transaction, daily, monthly). If the price exceeds any limit, a
BudgetExceededErroris thrown and no payment is made. - Sign — The SDK creates a cryptographic payment authorization using your wallet credentials. For x402, this is an EIP-3009 signature (gasless for you). For L402, this is a Lightning invoice payment.
- Deliver — The SDK re-sends the original request with the signed payment attached (in headers for x402, in a macaroon for L402).
- Verify & Settle — The server forwards the payment to a facilitator (e.g., Coinbase or x402.org) for on-chain verification and settlement. Once confirmed, the server returns the content.
-
Record — The SDK logs the payment amount in its budget tracker and returns the response to your agent, including payment metadata (
response.payment).
What the Agent Sees
From your agent’s perspective, nothing unusual happens. It calledfetch() and got data back:
200, and returns the response. response.payment is null.
Next Steps
- Architecture — how the SDK packages fit together
- Protocol Detection — the cascade that identifies x402, L402, and hybrid formats
- Budget & Safety — spending limits and safety guarantees