What the middleware does
For a protected route, the middleware handles the payment gate before your application performs paid work.Return payment requirements
When a request is unpaid, the route returns HTTP 402 with the price, asset, network, and
payTo address.Accept the paid retry
The buyer signs a guarantee with a unique request ID and retries with an x402 payment header.
Route configuration
payTo, confirm the advertised values in 4mica dashboard.
Fields you should make explicit
| Field | Your decision |
|---|---|
scheme | Use 4mica-credit for collateral-backed off-chain guarantees. |
price | Set the amount for this unit of work. Start small in sandbox. |
network | Use Base Sepolia (eip155:84532) for testing and Base (eip155:8453) for production when supported by your route. |
payTo | Use your wallet address that should receive payment. |
| Guarantee version | Use V1 for immediately payable work or V2 for validation-gated work. |
Pricing dynamic work
If the final cost depends on tokens, compute, data, or task complexity, use your application logic to quote before work begins. The buyer should see the price before paying.| Pattern | Example |
|---|---|
| Fixed price per route | $0.02 per summary. |
| Tiered routes | /basic, /pro, and /enterprise. |
| Quoted task | Your agent estimates cost and returns payment requirements for the accepted quote. |
| Metered work | You require prepayment or a credit cap before streaming or long-running execution. |
Delivery and logging
Log enough information to connect payment, request, and result.| Log field | Why it matters |
|---|---|
| Route and method | Shows which protected resource was called. |
| Request ID and guarantee ID | Connects the application request to the payment flow. |
Payer address and payTo address | Shows who paid and which seller address received the obligation. |
| Quoted price | Shows what the buyer authorized. |
| Payment header version | Helps debug client compatibility. |
| Verification and settle result | Shows whether payment validation succeeded. |
| Response status and delivery marker | Connects payment to the response you delivered. |