Examples
Metered chatbot
A chat product where every customer has their own balance and their own ceiling.
The shape most products start with: users sign up, get a small free balance, and can top up. Nobody can spend more than they have, and you can see who costs what.
Wiring it up
On sign-up, mint a key
Do this once, when the user is created, and store key.id on your user row. The secret is shown once, keep it wherever you keep their session material, not in a log.
On each request, call with that user's key
Your server holds the key and calls on the user's behalf. The gateway attributes the spend to them because of which key arrived, so there is nothing else to pass.
A stream that runs out mid-answer is aborted, not silently truncated. The client sees the stream end and a spend_cap_exceeded error frame, handle it the same way you handle the 402.
Show them what they spent
Either link to the hosted portal, or read the numbers yourself and render them in your own UI. Both read the same rows.