Gateway
Invoke a resource
POST /api/resources/{id}/invoke — call a free resource, or complete a paid one with an x402 proof.
/api/resources/{id}/invokepayment, not authenticationInvoke a resource exposed over http. The JSON body is the resource input. Free resources are delivered directly; paid ones answer 402 until the same request is repeated with a valid proof.
Request
Path
idstringrequiredHeaders
content-typeapplication/jsonPAYMENT-SIGNATUREbase64Agent-Authorizationbase64urlX-Request-IdstringBody
…objectExamples
curl -s http://localhost:8080/api/resources/weather_basic/invoke \
-X POST -H 'content-type: application/json' \
-d '{"city":"Berlin"}'Responses
Delivered
The merchant backend's status and body, relayed. After a settlement, the PAYMENT-RESPONSE header carries a base64 JSON summary:
HTTP/1.1 200 OK
content-type: application/json
PAYMENT-RESPONSE: eyJzdWNjZXNzIjp0cnVlLCJ0cmFuc2FjdGlvbiI6IjB4NGYy…
{ "report": "…" }{
"success": true,
"transaction": "0x4f2c…9ab1",
"network": "eip155:84532",
"status": "settled",
"provider": "x402",
"amount": "0.01",
"currency": "USDC"
}402 Payment Required
The body is the envelope below; the PAYMENT-REQUIRED header carries the x402 v2 PaymentRequired document as base64, which off-the-shelf x402 clients read. Sent with cache-control: no-store.
{
"status": "payment-required",
"code": "PAYMENT_REQUIRED",
"requestId": "…",
"resourceId": "market_report",
"message": "Payment of 0.01 USDC is required for resource \"market_report\". …",
"payment": {
"provider": "x402",
"version": "2",
"amount": "0.01",
"currency": "USDC",
"destination": "0x…",
"network": "eip155:84532",
"asset": "0x…",
"expiresAt": "…",
"accepts": [ /* x402 v2 PaymentRequirements, verbatim */ ],
"envelope": { /* x402 v2 PaymentRequired, verbatim */ }
}
}Errors
The error envelope with the code's HTTP status. A backend failure after settlement still sets PAYMENT-RESPONSE, so the buyer is never told less about their payment on the error path.
BACKEND_ERROR; redirects are not followed.