Manual x402 client flow (Python)
This page shows how to perform the entire x402 flow by hand in Python: no starter kit, nox402.http.clients wrappers. You send raw HTTP requests, decode the 402 response, build the payment payload, and resend with the payment signature.
For production youโll usually use the httpx or requests quickstarts; this tutorial is for agents or environments that need a minimal, dependency-light implementation or want to understand the protocol step by step.
1. Request the resource
Send a normal GET (or other method) to the protected URL. No special headers yet.2. Handle 402 and decode PAYMENT-REQUIRED
If the server requires payment, it returns 402 Payment Required and puts the payment options in the PAYMENT-REQUIRED header (base64-encoded JSON).3. Choose an accepted option
Pick one entry frompayment_required["accepts"] by network or scheme. For EVM (steps below), take an option whose network starts with eip155:. For Solana, take one whose network starts with solana: (see Solana (exact scheme) in step 4).
4. Build the payment payload
For the exact scheme on EVM, the client must produce an EIP-3009-style authorization and sign it with EIP-712 (see x402 Reference). The payload is sent in the PAYMENT-SIGNATURE header as base64-encoded JSON. You need a signer (e.g.eth_account or web3) to produce the signature and authorization fields. Example shape (simplified; real code must use correct domain, types, and signing):
Solana (exact scheme)
On Solana, you choose a Solana accept option (e.g.network starting with solana:), then build a partially-signed transaction and send it in the payload as base64. The transaction must contain these instructions in this order:
- SetComputeUnitLimit โ max 40,000 compute units
- SetComputeUnitPrice โ max 5 microlamports per compute unit
- TransferChecked โ token transfer (amount, mint, decimals, source, destination)
- Optional: Lighthouse (wallets like Phantom/Solflare may add up to two; merchants do not add these)
solders or solana-py) to build and sign the transaction. The payment payload is JSON with the transaction in payload.transaction as base64:
5. Resend the request with PAYMENT-SIGNATURE
Send the same request again (same URL and method), this time adding the PAYMENT-SIGNATURE header.6. Parse the response and PAYMENT-RESPONSE
On success the server returns 200 and may include PAYMENT-RESPONSE (base64-encoded settlement details). Decode the header and parse the JSON to get settlement info.Summary
| Step | Action |
|---|---|
| 1 | GET (or other method) the resource URL |
| 2 | If status is 402, decode PAYMENT-REQUIRED (base64 JSON) |
| 3 | Choose one entry from accepts |
| 4 | Build payment payload (EIP-712 sign for EVM exact scheme; or Solana tx) and base64-encode it |
| 5 | Resend the same request with PAYMENT-SIGNATURE header |
| 6 | On 200, use response body and optionally decode PAYMENT-RESPONSE |
Need help?
Join our Community
Have questions or want to connect with other developers? Join our Discord server.

