Dynamic pricing for x402 resources
Joaquim VergesWe've updated our x402 client/server stack to enable dynamic payments, perfect for AI APIs that need to charge on a per-token basis.
You can now pass a scheme property to verifyPayment() and settlePayment() which lets you control the payment scheme:
exact(default) - The client pays the exact amount specified in the payment requirements.upto(new) - The client pays any amount up to the specified maximum amount.
This new payment scheme is ideal for AI inference APIs where costs are dynamic based on the number of tokens used in each request.
This can be generalized to any type of API that uses variable amount of units of work, like RPC node APIs for example.
On the client side, the upto scheme is supported in v5.114.0 and above.
We recently open sourced a fully functional AI application that charges per tokens used, check out the repository on Github.
To learn more about how to set this up in your own projects, check out the documentation.