x402 Integration
x402 v2 integration via native extensions field and custom response header.
This section is advisory.
x402 is an HTTP 402-based payment protocol co-founded by Cloudflare and Coinbase (x402 Foundation), now including Google and Visa.
Note: This targets x402 v2, which introduces a native
extensionsfield in PaymentRequired responses.
Option 1 — Custom Response Header
Include the content hash in a custom HTTP header on the 402 response:
X-LCP-Hash: 0x7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069The X-LCP-Hash header carries the content hash in the 402 response (proposal phase). This approach works with any x402 version but is not part of the protocol's native structure.
Option 2 (Recommended) — x402 v2 extensions Field
x402 v2 includes a native extensions field in the PaymentRequired object. This is the recommended integration point because it is part of the protocol's own extensibility mechanism:
{
"extensions": {
"legalContext": {
"type": "sha256",
"value": "0x7f83b165..."
}
}
}The extensions field is the preferred integration point as it is part of the x402 v2 PaymentRequired schema and does not require custom headers.
x402 v2 Session Support
x402 v2 also supports reusable sessions — as with MPP, the legalContext SHOULD be established at session creation and governs all payments within the session.
Integration Flow
- Service returns 402 with a
PaymentRequiredobject containing thelegalContextin theextensionsfield (and optionally anX-LCP-Hashheader) - Agent fetches the terms document from the URL known via
/.well-known/legal-context.json(discovered earlier) - Agent computes SHA-256 of the downloaded document and compares to the hash value
- If match, agent saves the document locally and proceeds with payment via a
PaymentPayload SettlementResponsedelivered with the same hash reference confirming what was agreed