Available on crate feature
server only.Expand description
Axum middleware for enforcing x402 payments on protected routes (V2-only).
This middleware validates incoming payment headers using a configured x402 facilitator, verifies the payment, executes the request, and settles valid payments after successful execution. If the handler returns an error (4xx/5xx), settlement is skipped.
Returns a 402 Payment Required response if the request lacks a valid payment.
See X402Middleware for full configuration options.
For low-level interaction with the facilitator, see facilitator::FacilitatorClient.
§Configuration Notes
X402Middleware::with_price_tagsets the assets and amounts accepted for payment (static pricing).X402Middleware::with_dynamic_pricesets a callback for dynamic pricing based on request context.X402Middleware::with_base_urlsets the base URL for computing full resource URLs. If not set, defaults tohttp://localhost/(avoid in production).X402Middleware::with_supported_cache_ttlconfigures the TTL for caching facilitator capabilities.X402LayerBuilder::with_descriptionis optional but helps the payer understand what is being paid for.X402LayerBuilder::with_mime_typesets the MIME type of the protected resource (default:application/json).X402LayerBuilder::with_resourceexplicitly sets the full URI of the protected resource.
Re-exports§
pub use layer::X402LayerBuilder;pub use layer::X402Middleware;pub use pricing::DynamicPriceTags;pub use pricing::PriceTagSource;pub use pricing::StaticPriceTags;
Modules§
- facilitator
- A
r402::facilitator::Facilitatorimplementation that interacts with a remote x402 Facilitator over HTTP. - layer
- Axum middleware for enforcing x402 payments on protected routes.
- paygate
- Core payment gate logic for enforcing x402 payments (V2-only).
- pricing
- Price tag sources for the x402 payment gate.
Enums§
- Paygate
Error - Paygate error type that wraps verification and settlement errors.
- Verification
Error - Common verification errors shared between protocol versions.