How Extensions Work
x402 has two extension points that serve different roles in the payment flow:Resource Server Extensions
These run on the resource server (the service accepting payments) and hook into the HTTP payment lifecycle. AResourceServerExtension can intervene at three points:
- Declaration (
enrichDeclaration) — Called at route registration time. The extension can modify or narrow the route’s extension declaration based on transport context (e.g., Bazaar narrows the HTTP method). - 402 Response (
enrichPaymentRequiredResponse) — Called when the server returns402 Payment Required. The extension can add data to the response (e.g., signed offers, discovery metadata). - Settlement Response (
enrichSettlementResponse) — Called after successful payment. The extension can add data to thePAYMENT-RESPONSEheader (e.g., signed receipts, payment identifiers).
Facilitator Extensions
These run on the facilitator (the service that verifies and settles payments on behalf of the resource server). AFacilitatorExtension provides a key and is stored for use by mechanism implementations during verification and settlement. Gas sponsoring extensions are the primary example — they inject batch signing capabilities into the settlement flow so the facilitator can sponsor gas on behalf of the payer.
Registering an Extension (Server)
Extensions implement theResourceServerExtension interface and are registered via registerExtension:
key that identifies it in route declarations and response payloads.
The ResourceServerExtension Interface
Declaring Extensions on Routes
Extensions are declared per-route in the payment middleware configuration. Each extension’s declaration goes underextensions keyed by the extension’s key:
Which Hooks Do Extensions Use?
Not all extensions use the same hooks. Here’s how the built-in extensions map to the extension points:| Extension | enrichDeclaration | enrichPaymentRequiredResponse | enrichSettlementResponse | Facilitator |
|---|---|---|---|---|
| Bazaar | ✅ (narrows HTTP method) | — | — | ✅ (discovery cataloging) |
| EIP-2612 Gas Sponsoring | — | — | — | ✅ (batch signing) |
| ERC-20 Approval Gas Sponsoring | — | — | — | ✅ (batch signing) |
| Payment Identifier | — | ✅ | ✅ | — |
| Sign-In-With-X | — | — | — | — |
| Signed Offers & Receipts | — | ✅ (signs offers) | ✅ (signs receipts) | — |
Available Extensions
| Extension | Type | Description | SDK Support |
|---|---|---|---|
| Bazaar | Server + Facilitator | Discovery layer for x402 endpoints and MCP tools. Makes your services findable by AI agents and developers. | TypeScript, Go, Python |
| EIP-2612 Gas Sponsoring | Facilitator | Sponsors gas for EIP-2612 permit-based token transfers. | TypeScript |
| ERC-20 Approval Gas Sponsoring | Facilitator | Sponsors gas for ERC-20 approval-based token transfers. | TypeScript |
| Payment Identifier | Server + Client | Attaches a unique identifier to each payment for tracking, reconciliation, and idempotency. | TypeScript, Go, Python |
| Sign-In-With-X | Server + Client | CAIP-122 wallet authentication. Lets clients prove wallet ownership to access previously purchased content without repaying. | TypeScript |
| Signed Offers & Receipts | Server + Client | Signs offers on 402 responses and receipts on 200 responses, producing cryptographic proof-of-interaction artifacts. | TypeScript |
Building a Custom Extension
To create your own extension:- Define the extension object implementing
ResourceServerExtension - Choose a unique key — this identifies your extension in route declarations and response payloads
- Implement the hooks you need —
enrichDeclaration,enrichPaymentRequiredResponse,enrichSettlementResponse - Create a declare function — a helper that returns the route-level configuration for your extension
- Register it on the
x402ResourceServerviaregisterExtension - Submit a pull request to coinbase/x402 — extensions must be reviewed and approved by the x402 maintainers before they are included in the SDK
extensions["my-extension"].
Further Reading
- x402 SDK Features — Extension support across TypeScript, Go, and Python
- Extension Specs — Protocol-level extension specifications
- @x402/extensions package — TypeScript implementation source