Skip to main content
Copy-paste patterns for validating payment requests for APIs, agents/tools, and protected resources.
Looking for framework-specific implementations?

Basic validation (framework-agnostic)

At a minimum, validation has three steps:
  1. Extract x402 token from the payment-signature header
  2. Verify permissions using the facilitator
  3. Return 402 Payment Required when missing/invalid

Validation with minimum credits

Check that the user has enough credits for the operation:

Validation response handling

Handle all possible validation outcomes:

Caching validation results

For high-traffic endpoints, cache validation briefly:

Next steps

Charge Credits

Deduct credits for requests

Subscription Access

Time-based access patterns