Payment Protocol
Multiple interaction models for using the X-Cashu header to pay for access to LLM or other AI services over HTTP.
This section describes multiple interaction models ("protocols") for using the X-Cashu header to pay for access to LLM or other AI services over HTTP. It also standardizes an endpoint for model and pricing discovery, enabling wallet-aware clients to act responsibly based on current rates.
Summary:
Each API request is accompanied by a freshly-issued Cashu note in the X-Cashu header, representing the payment for only that request. The provider server verifies, redeems (burns) the note, and returns a new note as change if any remains. Payments are not reused or linked across calls.
Security:
- Statelessness and Single-use means no long-lived token risk
- No provider-side wallet tracking (only redemption)
- This is the highest privacy and anti-replay approach
Flow (Sequence Diagram):
Summary:
A Cashu token with a nonzero balance is retrieved from client storage (database or external service) and sent with every request. The provider tracks the balance of this particular token, deducts the cost on each invocation, and replies with HTTP 402 if the balance is insufficient. The client updates the token balance in storage and manages issuing new tokens as necessary.
Security:
- Server must manage reliable per-token state, increasing operational complexity
- Slightly decreased privacy as token may correlate requests
Flow:
Summary:
Clients request an API key by paying ecash upfront to prepay for service credits. Once the API key is obtained, clients use only the API key for requests without sending ecash with each call. When credits are exhausted (HTTP 402 response), clients purchase a new API key or top up their existing account.
Flow:
| Protocol | Privacy | Server State | Payment Granularity | Difficulty | Appropriate Usage |
|---|---|---|---|---|---|
| Single-use (Stateless) | High | None | Exact per-request | Mid | Maximum security |
| Persistent-Token | Mid | Per-token | Up to token value | Low | High-frequency calls |
| Prepaid Account/Top-up | Mid | Per-account | Up to top-up size | Low | Enterprise/bulk use |