x402 has two protocol versions. Version 2 is preferred for new integrations. Faremeter supports both versions simultaneously, and the middleware can serve v1 and v2 clients at the same time.Documentation Index
Fetch the complete documentation index at: https://docs.faremeter.xyz/llms.txt
Use this file to discover all available pages before exploring further.
At a glance
| v1 | v2 | |
|---|---|---|
| Client header | X-PAYMENT | PAYMENT-SIGNATURE |
| Server requirement header | (in response body only) | PAYMENT-REQUIRED |
| Server response header | X-PAYMENT-RESPONSE | PAYMENT-RESPONSE |
| Payload location | Base64-encoded JSON in header | Base64-encoded JSON in header |
Payload includes accepted | No | Yes — echoes the requirement the client chose |
| Status | Supported | Preferred |
Version 1
In v1, the server returns payment requirements in the402 response body as JSON:
X-PAYMENT header:
Version 2
v2 uses dedicated HTTP headers for the payment protocol, separating payment data from the response body. The server returns requirements in both the response body and thePAYMENT-REQUIRED header. On successful payment, it includes a PAYMENT-RESPONSE header with the settlement result.
The client sends its payment proof in the PAYMENT-SIGNATURE header. The v2 payload includes the accepted requirement the client chose, plus resource information:
accepted requirement in the payload lets the facilitator verify that the client is paying for the correct requirement without relying on the server to re-send it.
Configuring version support
The middleware usesresolveSupportedVersions() to determine which protocol versions to serve. By default, v1 is enabled and v2 is disabled.
createMiddleware or handleMiddlewareRequest:
With createMiddleware (Express)
With handleMiddlewareRequest
Migrating from v1 to v2
- Enable both versions during the transition so existing v1 clients continue to work:
- Update clients to use the latest
@faremeter/ridesor@faremeter/fetch, which automatically negotiate the highest supported version. - Disable v1 once all clients have migrated:
Version adapters
If you are running your own facilitator and need to convert between v1 and v2 formats, use the adapter functions from@faremeter/types/x402-adapters:
| Function | Direction |
|---|---|
adaptPayloadV1ToV2() | v1 payment payload to v2 |
adaptPaymentRequiredResponseV1ToV2() | v1 requirements response to v2 |
adaptSettleResponseV1ToV2() | v1 settle response to v2 |
adaptSettleResponseV2ToV1() | v2 settle response to v1 |
adaptSettleResponseV2ToV1Legacy is deprecated. Use adaptSettleResponseV2ToV1 for spec-compliant v1 output.Further reading
- How x402 Works — The full payment flow.
- x402 v1 Types API Reference — v1 type definitions.
- x402 v2 Types API Reference — v2 type definitions.
- Version Adapters API Reference — Conversion functions.