Files
ssmithxandClaude Opus 5.5 3fee084944 fix(routstr): pay per request with X-Cashu so change is refunded
Both Routstr clients paid with `Authorization: Bearer <cashu token>`.
Against routstr-core v0.5.0 (the version the public aggregator
routstr.otrta.me reports: 0.5.0+gd65f8cd) a Bearer token does not pay for
one request: it opens a server-side API-key balance funded by the whole
token and returns no change. Change comes back in the `X-Cashu` response
header only for the per-request `X-Cashu: <token>` flow.

- AIUI (`routstr_proxy.rs`) already redeemed `x-cashu` change, but never
  received any, so the deliberately overquoted remainder of every request
  (+20% margin, priced for the full 1024-token cap) was recorded as spent
  and left on the aggregator.
- The assistant fallback (`backends/routstr.rs`) never looked for change
  and never reclaimed a token after a failed send.

Both now send `X-Cashu`. The assistant redeems the change (or the whole
token, which v0.5.0 returns in `x-cashu` when it refuses a request) and
credits it back to the allowance, which it debits in full before sending.

Observed against a local routstr-core v0.5.0 with a fake-Lightning mint:
X-Cashu 20-sat token -> 70 msat charged, 17 sat change redeemed; Bearer
20-sat token -> 53 msat charged, no change header, 18947 msat left on the
provider-side account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 04:40:34 +00:00
..
2026-10-10 16:43:31 -04:00