What the middleware does
For a protected route, the middleware handles the payment gate before your application performs paid work.1
Return payment requirements
When a request is unpaid, the route returns HTTP 402 with the price, asset, network, and
payTo address.2
Accept the paid retry
The buyer signs a guarantee with a unique request ID and retries with an x402 payment header.
3
Verify and settle
The middleware verifies the signed guarantee and settles through the facilitator.
4
Run your handler
Your paid handler runs only after payment validation succeeds.
Route configuration
payTo, confirm the advertised values in 4mica dashboard.
Fields you should make explicit
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.
Keep the payment requirement honest. If the buyer paid for one request, do not silently perform more work that requires a larger charge.
Delivery and logging
Log enough information to connect payment, request, and result.
These records are how you answer “which request was paid for?” and “what response did the agent deliver?”
Keep these logs close to dashboard settlement records so support can trace buyer claims quickly.