Facilitator Integration
Any x402 facilitator can integrate with the sponsored-access system. The Dexter facilitator is the reference implementation, but the ad-network service is designed to work with multiple facilitators.
What You Need
- Your facilitator must implement the standard x402
/settleendpoint - After a successful settlement, you call the ad-network match API
- If a campaign matches, you inject the recommendation into
SettlementResponse.extensions - You report the settlement event to the ad-network service
Step-by-Step
1. Register with the Ad Network
Contact us to get an API key. You will receive:
- A
facilitatorIdidentifying your facilitator - An API key for authenticating with the ad-network service
- The base URL for the match and events APIs
2. Call the Match API After Settlement
After your facilitator settles a payment on-chain, call:
The response is either:
Or:
Use a timeout of 2 seconds or less. If the call fails or times out, skip the recommendation and return the normal settlement response. Never block settlement on the match API.
3. Inject into SettlementResponse
If a campaign matched, add the recommendation to SettlementResponse.extensions["sponsored-access"]:
The standard x402 protocol delivers the full SettlementResponse to the client via the PAYMENT-RESPONSE header (HTTP) or _meta["x402/payment-response"] (MCP). No additional work is needed to deliver the recommendation to the client.
4. Report the Settlement Event
After injecting the recommendation, fire a POST to the events endpoint:
This should be fire-and-forget. Do not wait for a response. Do not block the settlement response on this call.
5. Optional: Conversion Tracking
For end-to-end conversion tracking, your facilitator can maintain an in-memory cache of recent recommendations (payer wallet to recommended resource URL). When a subsequent settlement arrives where the payer calls the recommended resource, report the conversion:
Reference Implementation
The Dexter facilitator implementation is at:
src/sponsoredAccess.tsin dexter-facilitator
This is a single file (~250 lines) that handles matching, injection, event reporting, and conversion tracking. It can be used as a reference for implementing the same logic in any x402 facilitator.
Requirements
- Your facilitator must return the full
SettlementResponseincludingextensionsto the resource server - The standard
@x402/coremiddleware already forwards the full response to clients - The match API call adds ~20ms latency to the settle path (measured in production)
- Event reporting is async and adds zero latency